Lasso model results
Now that you've trained the Lasso model, you'll score its predictive capacity (\(R^2\)) on the test set and count how many features are ignored because their coefficient is reduced to zero.
The X_test
and y_test
datasets have been pre-loaded for you.
The Lasso()
model and StandardScaler()
have been instantiated as la
and scaler
respectively and both were fitted to the training data.
Este exercício faz parte do curso
Dimensionality Reduction in Python
Instruções do exercício
- Transform the test set with the pre-fitted scaler.
- Calculate the \(R^2\) value on the scaled test data.
- Create a list that has True values when coefficients equal 0.
- Calculate the total number of features with a coefficient of 0.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Transform the test set with the pre-fitted scaler
X_test_std = scaler.____
# Calculate the coefficient of determination (R squared) on X_test_std
r_squared = la.____(____, ____)
print(f"The model can predict {r_squared:.1%} of the variance in the test set.")
# Create a list that has True values when coefficients equal 0
zero_coef = la.____ == ____
# Calculate how many features have a zero coefficient
n_ignored = sum(____)
print(f"The model has ignored {n_ignored} out of {len(la.coef_)} features.")