MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Explainable AI in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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)
Edit dan Jalankan Kode