0
0
ML Pythonml~20 mins

Elastic Net regularization in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Elastic Net Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Elastic Net Regularization
Which statement best describes the Elastic Net regularization technique in machine learning?
AIt randomly drops features during training to prevent overfitting.
BIt uses only L1 penalty to shrink coefficients to zero, promoting feature selection.
CIt applies only L2 penalty to reduce coefficient magnitude without setting any to zero.
DIt combines L1 and L2 penalties to encourage both sparsity and grouping of correlated features.
Attempts:
2 left
💡 Hint
Think about how Elastic Net mixes two types of penalties.
Predict Output
intermediate
2:00remaining
Output of Elastic Net Regression Coefficients
What will be the output coefficients after fitting Elastic Net regression with alpha=1.0 and l1_ratio=0.5 on the given data?
ML Python
from sklearn.linear_model import ElasticNet
import numpy as np

X = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
y = np.array([3, 5, 7, 9])

model = ElasticNet(alpha=1.0, l1_ratio=0.5, random_state=0)
model.fit(X, y)
coefficients = model.coef_
print(coefficients)
A[0.0 1.5]
B[0.5 1.0]
C[0.8 1.2]
D[1.0 0.0]
Attempts:
2 left
💡 Hint
Check how Elastic Net balances L1 and L2 penalties with given parameters.
Hyperparameter
advanced
2:00remaining
Effect of l1_ratio in Elastic Net
What happens to the Elastic Net model when the l1_ratio parameter is set to 1.0?
AThe model applies both L1 and L2 penalties equally.
BThe model behaves like Ridge regression, using only L2 penalty.
CThe model behaves like Lasso regression, using only L1 penalty.
DThe model ignores regularization and fits ordinary least squares.
Attempts:
2 left
💡 Hint
l1_ratio controls the mix between L1 and L2 penalties.
Metrics
advanced
2:00remaining
Choosing Regularization Strength Alpha
Which method is best to select the optimal alpha parameter for Elastic Net to balance bias and variance?
AUse cross-validation to find alpha that minimizes validation error.
BSet alpha to zero to avoid any regularization.
CChoose the largest alpha to maximize sparsity regardless of error.
DRandomly pick alpha without validation.
Attempts:
2 left
💡 Hint
Think about how to avoid overfitting and underfitting.
🔧 Debug
expert
2:00remaining
Debugging Elastic Net Model Training Error
You run this code but get a ValueError: 'alpha must be positive'. Which option fixes the error?
ML Python
from sklearn.linear_model import ElasticNet
model = ElasticNet(alpha=0, l1_ratio=0.5)
model.fit([[1, 2], [3, 4]], [5, 6])
AChange alpha to a positive value like 0.1.
BSet l1_ratio to 0 to disable L1 penalty.
CRemove the alpha parameter entirely.
DChange input data to integers only.
Attempts:
2 left
💡 Hint
Check the error message about alpha value.