ComenzarEmpieza gratis

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 ejercicio forma parte del curso

Dimensionality Reduction in Python

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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.")
Editar y ejecutar código