Project · 24 steps · Medium

NumPy House Price Regression

Build a complete end-to-end house-price regressor in pure NumPy: clean tabular features, engineer simple derived and categorical encodings, split reproducibly, fit OLS via the normal equation, and report MAE, RMSE, R-squared, plus residual stats on held-out homes.

Each step is one function with tests. Your code runs in the browser, and every step builds on the ones before it.

Part 1: Data Cleaning

Impute missing values and clip obvious column-wise outliers so the design matrix is finite and stable.

  1. impute_nan_with_mean
  2. compute_iqr_bounds
  3. clip_columns

Part 2: Feature Engineering

Build derived ratio features, one-hot encode categoricals, standardize numerics, and add a bias column.

  1. make_ratio_feature
  2. append_column
  3. one_hot_encode
  4. fit_standardizer
  5. apply_standardizer
  6. add_bias_column

Part 3: Reproducible Splits

Create shuffled train/validation/test index partitions and materialize the corresponding row subsets.

  1. make_shuffled_indices
  2. partition_indices
  3. subset_xy

Part 4: OLS Regressor

Fit an ordinary-least-squares linear model with the normal equation and generate predictions.

  1. ols_fit
  2. ols_predict

Part 5: Metrics and Residuals

Compute MAE, RMSE, R-squared, and a compact numeric residual summary on held-out predictions.

  1. mean_absolute_error
  2. root_mean_squared_error
  3. r_squared
  4. residual_summary

Part 6: End-to-End Pipeline

Wire cleaning, features, splitting, fitting, and evaluation into one pipeline that returns metrics and test predictions.

  1. prepare_cleaned_features
  2. assemble_feature_matrix
  3. make_train_val_test
  4. standardize_and_add_bias
  5. evaluate_predictions
  6. house_price_pipeline