Polynomial Regression

<aside> 💡 Polynomial regression = Polynomial transformation + Linear Regression

</aside>

Polynomial Features

Training

from sklearn.linear_model import LinearRegression
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures

# Two steps:
# 1. Polynomial features of the desired degree (here degree=2)
# 2. Linear regression

poly_model = Pipeline([
								('polynomial_transform', PolynomialFeatures(degree=2))),
								('linear_regression', LinearRegression())])

# Train with feature matrix X_train and label vector y_train
poly_model.fit(X_train, y_train)

Interaction Features

from sklearn.preprocessing import PolynomialFeatures
poly_transform = PolynomialFeatures(degree=2, interaction_only=True)

Hyperparameter Tuning

Setting hyperparameters

Select hyperparameters that result in the best cross-validation scores.