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.
impute_nan_with_meancompute_iqr_boundsclip_columns
Part 2: Feature Engineering
Build derived ratio features, one-hot encode categoricals, standardize numerics, and add a bias column.
make_ratio_featureappend_columnone_hot_encodefit_standardizerapply_standardizeradd_bias_column
Part 3: Reproducible Splits
Create shuffled train/validation/test index partitions and materialize the corresponding row subsets.
make_shuffled_indicespartition_indicessubset_xy
Part 4: OLS Regressor
Fit an ordinary-least-squares linear model with the normal equation and generate predictions.
ols_fitols_predict
Part 5: Metrics and Residuals
Compute MAE, RMSE, R-squared, and a compact numeric residual summary on held-out predictions.
mean_absolute_errorroot_mean_squared_errorr_squaredresidual_summary
Part 6: End-to-End Pipeline
Wire cleaning, features, splitting, fitting, and evaluation into one pipeline that returns metrics and test predictions.
prepare_cleaned_featuresassemble_feature_matrixmake_train_val_teststandardize_and_add_biasevaluate_predictionshouse_price_pipeline