0
0
ML Pythonml~10 mins

Elastic Net regularization 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 ElasticNet model from scikit-learn.

ML Python
from sklearn.linear_model import [1]
Drag options to blanks, or click blank then click option'
AElasticNet
BLinearRegression
CLogisticRegression
DRidge
Attempts:
3 left
💡 Hint
Common Mistakes
Importing LinearRegression instead of ElasticNet.
Confusing ElasticNet with LogisticRegression.
2fill in blank
medium

Complete the code to create an ElasticNet model with alpha set to 0.5.

ML Python
model = ElasticNet([1]=0.5)
Drag options to blanks, or click blank then click option'
Aalpha
Bmax_iter
Cl1_ratio
Dfit_intercept
Attempts:
3 left
💡 Hint
Common Mistakes
Using l1_ratio instead of alpha for regularization strength.
Setting max_iter instead of alpha.
3fill in blank
hard

Fix the error in the code to fit the ElasticNet model on training data X_train and y_train.

ML Python
model = ElasticNet(alpha=0.1, l1_ratio=0.7)
model.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Ascore
Bfit
Ctransform
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using predict instead of fit to train the model.
Using transform which is not available for ElasticNet.
4fill in blank
hard

Fill both blanks to create a dictionary of coefficients and intercept from the trained ElasticNet model.

ML Python
model = ElasticNet(alpha=0.2, l1_ratio=0.5).fit(X, y)
result = {"coefficients": model.[1], "intercept": model.[2]
Drag options to blanks, or click blank then click option'
Acoef_
Bintercept_
Cfit
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit or predict instead of coef_ or intercept_.
Confusing attribute names without underscores.
5fill in blank
hard

Fill all three blanks to compute the mean squared error (MSE) of ElasticNet predictions on test data.

ML Python
from sklearn.metrics import {{BLANK_1 }}
predictions = model.predict(X_test)
mse = [2](y_test, {{BLANK_3}})
Drag options to blanks, or click blank then click option'
Amean_squared_error
Bpredictions
Cy_test
Dr2_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using r2_score instead of mean_squared_error.
Swapping true and predicted values in the function.