BaşlayınÜcretsiz Başlayın

Computing feature importance with decision trees

You built a decision tree classifier to identify patients at risk of heart disease using the heart disease dataset. Now you need to explain the model by analyzing feature importance to determine the key factors for predicting heart disease, enabling more targeted healthcare interventions.

matplotlib.pyplot has been imported as plt. X_train and y_train are pre-loaded for you.

Bu egzersiz

Explainable AI in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Extract the feature importances from the model.
  • Plot the feature_importances for the given feature_names.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

model = DecisionTreeClassifier(random_state=42)
model.fit(X_train, y_train)

# Derive feature importances
feature_importances = ____
feature_names = X_train.columns

# Plot the feature importances
____
plt.show()
Kodu Düzenle ve Çalıştır