Back to Modeling: Regression and Beyond

Linear Regression — The Math, Not Just the API

What `LinearRegression().fit()` actually does, and the assumptions that make it valid. FIND_VIDEO: search 'linear regression OLS assumptions' — recommended channel: StatQuest / 3Blue1Brown. Aim for 11 min or under.

27 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. Three Core StepsLinear regression involves fitting a line using least squares, calculating R-squared, and determining the P-value.
  2. Least Squares MethodThe least squares method finds the line rotation that minimizes the Sum of Squared Residuals (SS).
  3. SS Mean CalculationSS Mean measures the total variation around the average value of the response variable (Y).
  4. SS Fit CalculationSS Fit measures the unexplained variation remaining around the fitted least squares line.
  5. R-Squared FormulaR-squared quantifies the percentage reduction in variance achieved by the fitted model.
  6. Adjusted R-SquaredBecause adding parameters never worsens R-squared, Adjusted R-squared is used to penalize overly complex models.
  7. Need for P-ValueA P-value is required to determine if a high R-squared value is statistically significant or merely due to random chance.
  8. F-Statistic RatioThe F-statistic is calculated as the ratio of explained variation to the variation that remains unexplained by the model.
PDF notes

Frequently asked questions

Why is the fitting method called 'Least Squares'?

It finds the line rotation that results in the minimum possible sum of the squared residuals. This minimizes the overall error.

What does an R-squared of 0.6 mean?

It means 60% of the variation in the response variable (e.g., mouse size) is explained by the predictor variable (e.g., mouse weight).

Why do we square the residuals before summing them?

Squaring ensures all distances are positive and heavily penalizes large errors, making the minimization process effective.

Does adding parameters always improve the fit?

The calculated R-squared will never decrease, because least squares can set useless parameters to zero, effectively ignoring them.

How does the F-statistic differ from R-squared?

R-squared compares explained variation to total variation. The F-statistic compares explained variation to unexplained variation.