Complete the code to import the class for polynomial features.
from sklearn.preprocessing import [1]
The PolynomialFeatures class is used to generate polynomial and interaction features from the original features.
Complete the code to create a polynomial features transformer of degree 3.
poly = PolynomialFeatures(degree=[1])Setting degree=3 creates polynomial features up to cubic terms.
Fix the error in the code to fit the polynomial regression model.
model = LinearRegression()
X_poly = poly.[1](X)
model.fit(X_poly, y)We first fit the poly transformer separately, then use transform to convert X to polynomial features before fitting the model.
Fill both blanks to create a pipeline that first transforms features then fits a linear regression.
from sklearn.pipeline import Pipeline pipeline = Pipeline([ ('poly', [1](degree=2)), ('linear', [2]()) ])
The pipeline first applies PolynomialFeatures to create polynomial terms, then fits a LinearRegression model.
Fill all three blanks to train the pipeline and predict on test data.
pipeline.fit([1], [2]) predictions = pipeline.[3](X_test)
We fit the pipeline on training features and targets, then use predict to get predictions on test features.