Aan de slagGa gratis aan de slag

Coefficients vs. permutation importance

Now, you will compare the patterns identified by permutation importance with the model coefficients from a logistic regression trained on the heart disease dataset. A helper function plot_importances() is called at the end of the script to plot importances on the same plot.

X containing the features and y containing the labels, and the logistic regression model have been pre-loaded for you. matplotlib.pyplot has been imported as plt.

Deze oefening maakt deel uit van de cursus

Explainable AI in Python

Cursus bekijken

Oefeninstructies

  • Compute the coefficients of the logistic regression model.
  • Compute the permutation importance with 20 repeats using a random_state of 1.
  • Compute the average permutation importance across all repeats.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

from sklearn.inspection import permutation_importance

# Extract and store model coefficients
coefficients = ____

# Compute permutation importance on the test set
perm_importance = ____

# Compute the average permutation importance
avg_perm_importance = ____

plot_importances(coefficients, avg_perm_importance)
Code bewerken en uitvoeren