開始使用免費開始

員工離職模型比較

在這個練習中,你要使用經過剪枝的樹(max_depth=7)比較「balanced」與「imbalanced」(預設)兩種模型。imbalanced 模型已經替你計算了 recallROC/AUC 分數。請為 balanced 模型完成相同步驟。

  • 變數 features_traintarget_trainfeatures_testtarget_test 已經在你的工作環境中。
  • 已替你訓練好一個 imbalanced 模型,且其預測結果已儲存為 prediction
  • recall_score()roc_auc_score() 函式已替你匯入。

本練習屬於課程

HR 分析:用 Python 預測員工流失

檢視課程

練習說明

  • 初始化 balanced 模型,將最大深度設為 7,隨機種子設為 42
  • 使用訓練集將其擬合到訓練資料元件。
  • 使用測試集進行預測。
  • 印出 recall 分數ROC/AUC 分數。

動手互動練習

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

# Print the recall score
print(recall_score(target_test,prediction))
# Print the ROC/AUC score
print(roc_auc_score(target_test,prediction))

# Initialize the model
model_depth_7_b = 
# Fit it to the training component
model_depth_7_b.fit(____,____)
# Make prediction using test component
prediction_b = 
# Print the recall score for the balanced model
print(____)
# Print the ROC/AUC score for the balanced model
print(____)
編輯並執行程式碼