0
0
ML Pythonml~10 mins

Polynomial regression pipeline in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the class for polynomial features.

ML Python
from sklearn.preprocessing import [1]
Drag options to blanks, or click blank then click option'
AStandardScaler
BLinearRegression
CPolynomialFeatures
Dtrain_test_split
Attempts:
3 left
💡 Hint
Common Mistakes
Importing LinearRegression instead of PolynomialFeatures
Importing train_test_split which is for splitting data
Importing StandardScaler which is for scaling features
2fill in blank
medium

Complete the code to create a polynomial features transformer of degree 3.

ML Python
poly = PolynomialFeatures(degree=[1])
Drag options to blanks, or click blank then click option'
A3
B2
C1
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using degree 1 which does not add polynomial features
Using degree 2 which adds only quadratic terms
Using degree 4 which is higher than requested
3fill in blank
hard

Fix the error in the code to fit the polynomial regression model.

ML Python
model = LinearRegression()
X_poly = poly.[1](X)
model.fit(X_poly, y)
Drag options to blanks, or click blank then click option'
Afit
Btransform
Cfit_transform
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit_transform instead of transform causing double fitting
Using fit which returns the transformer itself, not transformed data
Using predict which is for making predictions
4fill in blank
hard

Fill both blanks to create a pipeline that first transforms features then fits a linear regression.

ML Python
from sklearn.pipeline import Pipeline
pipeline = Pipeline([
    ('poly', [1](degree=2)),
    ('linear', [2]())
])
Drag options to blanks, or click blank then click option'
APolynomialFeatures
BLinearRegression
CStandardScaler
DLogisticRegression
Attempts:
3 left
💡 Hint
Common Mistakes
Using StandardScaler instead of PolynomialFeatures for the first step
Using LogisticRegression which is for classification
Swapping the order of steps
5fill in blank
hard

Fill all three blanks to train the pipeline and predict on test data.

ML Python
pipeline.fit([1], [2])
predictions = pipeline.[3](X_test)
Drag options to blanks, or click blank then click option'
AX_train
By_train
Cpredict
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using y_train as first argument to fit
Using fit instead of predict for predictions
Using X_test in fit instead of training data