Skip to content

About

Build a from-scratch multiple linear regression trainer in pure NumPy: standardize features, minimize MSE with batch gradient descent and early stopping, compare against the normal equation, and report MAE, RMSE, and R-squared via a reusable model API.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

37 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

NumPy Multiple Linear Regression GD

Build a from-scratch multiple linear regression trainer in pure NumPy: standardize features, minimize MSE with batch gradient descent and early stopping, compare against the normal equation, and report MAE, RMSE, and R-squared via a reusable model API.

How to run

python scaffold.py

Steps

  • 1. shuffle_xy
  • 2. split_train_val_test
  • 3. compute_feature_stats
  • 4. standardize_features
  • 5. add_bias_column
  • 6. prepare_design_matrix
  • 7. predict_linear
  • 8. mse_loss
  • 9. mse_gradient
  • 10. normal_equation
  • 11. initialize_weights
  • 12. gd_step
  • 13. epoch_train_val_losses
  • 14. update_early_stop_state
  • 15. init_training_state
  • 16. run_one_epoch
  • 17. train_batch_gd
  • 18. mean_absolute_error
  • 19. root_mean_squared_error
  • 20. r_squared
  • 21. evaluate_regression
  • 22. learning_curve_data
  • 23. weights_l2_distance
  • 24. create_lr_model
  • 25. fit_lr_model
  • 26. predict_lr_model
  • 27. score_lr_model
  • 28. compare_with_normal_equation

Results

Splits: 90 30 30
Sample preds: [-4.9349 -2.1614 -1.1088 -3.5913  1.7047]
Sample trues: [-4.8688 -2.2391 -0.8235 -3.5582  1.6763]
Test MAE/RMSE/R2: {'mae': 0.09220147681923264, 'rmse': 0.12202512653831676, 'r2': 0.9985479787094949}
GD vs normal-eq L2 gap: 0.005860423059766929
Final train/val MSE: 0.010137750731524809 0.012253596422242757
Epochs run: 81

About

Build a from-scratch multiple linear regression trainer in pure NumPy: standardize features, minimize MSE with batch gradient descent and early stopping, compare against the normal equation, and report MAE, RMSE, and R-squared via a reusable model API.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages