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
.
This exercise is part of the course
Explainable AI in Python
Exercise instructions
- 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.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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)