開始使用免費開始

用邏輯斯回歸計算特徵影響力

延續你在保險公司的專案,你建立了一個預測模型,用來判斷個體是否為吸菸者。現在,你需要分析這個模型,找出影響吸菸與否的關鍵因素,協助公司更精準評估風險,並據此調整保險方案。

matplotlib.pyplot 已以 plt 匯入。X_trainy_train 已經為你載入。

本練習屬於課程

Python 的 Explainable AI

檢視課程

練習說明

  • 從模型中擷取 coefficients
  • 針對給定的 feature_names 繪製這些 coefficients

動手互動練習

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

scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)

model = LogisticRegression()
model.fit(X_train_scaled, y_train)

# Derive coefficients
coefficients = ____
feature_names = X_train.columns

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