Regression with gradient descent
Gradient descent can be a good alternative to ordinary least squares for optimizing the loss function of a linear model. This is particularly true when working with very large datasets. In this section, we will use gradient descent with the land temperatures dataset, mainly to demonstrate how to use it and to give us another opportunity to explore exhaustive grid searches. Let’s get started:
- First, we will load the same libraries we have been working with so far, plus the stochastic gradient descent regressor from scikit-learn:
import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.linear_model import SGDRegressor from sklearn.compose import TransformedTargetRegressor from sklearn.pipeline import make_pipeline from sklearn.impute import KNNImputer from sklearn.model_selection import GridSearchCV import os import sys sys.path.append(os.getcwd...