Predict a Number: Regression from Scratch to Regularisation
Who it is for
What you will achieve
Prerequisites
Curriculum
- Step 1: Linear Regression and the Cost Function: Draw a Line, Score It
Draw a straight line through six kids' ages and weights, measure every miss, and turn the misses into one score, the mean squared error. Then let np.polyfit find the line with the lowest score.
- Step 2: Gradient Descent Explained: Feel the Slope, Step Downhill
Instead of handing over the best line, let the computer walk to it: measure the slope of the cost, step downhill with a learning rate, repeat. Shown step by step on six kids' ages and weights.
- Step 3: Linear Regression in scikit-learn: Fit, Predict and Read the Price Tags
Predict a yearly medical bill with scikit-learn's LinearRegression: first from age alone, then from every column inside a pipeline. Each coefficient reads like a price tag, and smoker_yes is by far the biggest.
- Step 4: Regression Metrics: MAE, RMSE, R-squared and the Baseline to Beat
Score a regression model honestly: MAE, MSE and RMSE from four darts, then the insurance model on 268 test people, a DummyRegressor baseline to beat, R-squared and adjusted R-squared, and a residual plot.
- Step 5: Polynomial Regression, Overfitting and Underfitting: Bend the Line, Watch the Test Score
Give a linear model extra columns with PolynomialFeatures and it can bend. Then watch train and test scores split apart: degrees 1, 2 and 16 on Canada's income per person, and degrees 1 to 5 on the insurance model.
- Step 6: Regularisation with Ridge and Lasso: Put a Price on Big Weights
The degree-4 insurance model overfits (train 0.876, test 0.754). Ridge shrinks every weight and lifts the test score to 0.843; Lasso switches off all but 40 of 495 columns and reaches 0.862.