開始使用免費開始

使用隨機森林計算特徵重要性

你是一家財務顧問公司的資料科學家,已經建立一個隨機森林分類器,用來依照個人收入水準進行分類。現在,你需要透過分析特徵重要性來解釋模型,找出影響收入預測的關鍵因素,以便更精準地進行市場區隔並提升策略決策品質。

matplotlib.pyplot 已匯入為 pltX_trainy_train 已為你預先載入。

本練習屬於課程

Python 的 Explainable AI

檢視課程

練習說明

  • model 萃取特徵重要性。
  • 繪製 feature_importances

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

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

# Derive feature importances
feature_importances = ____

# Plot the feature importances
____
plt.show()
編輯並執行程式碼