⚡ Linear Regression with sklearn

These are Noah's notes on how to implement a linear regression model using the scikit-learn library. This demonstration will help you understand how scikit-learn simplifies the process of training, evaluating, and using linear regression models.

The interactive notebook includes:

  • Synthetic data generated from a line we plant ourselves ($y = 4 + 3x$), so the result can be checked.
  • Splitting the data into training and test sets with train_test_split.
  • Training a LinearRegression model with a single call to fit(), and comparing what it learns with the planted line.
  • Evaluation on unseen data with MSE and R², and a comparison with the training error.
  • Visualization of the training data, the test data and the regression line.
  • Predictions for new data, and the difference between interpolation and extrapolation.

Want to modify the code and experiment on your own?
Open the notebook in Google Colab

Bibliography