始める無料で始める

最良のモデルを開発して評価する

第3章で、以下のパラメータを使うとモデル性能が向上することがわかりました。

  • max_depth = 8,
  • min_samples_leaf = 150,
  • class_weight = "balanced"

この章では、いくつかの特徴量は影響が小さいことがわかりました。限られた重要な特徴量だけでも高い精度で予測できると判断し、それに合わせて学習用・テスト用データを更新し、features_train_selectedfeatures_test_selected の変数を作成しました。

これらの情報を踏まえて、従業員の離職を予測するための最良のモデルを作成し、適切な指標で評価しましょう。

features_train_selectedfeatures_test_selected はワークスペースに用意されています。また、recall_scoreroc_auc_score 関数はインポート済みです。

この演習はコースの一部です

HRアナリティクス:Pythonで従業員離職を予測する

コースを見る

演習の手順

  • 説明で指定されたパラメータを使って最良のモデルを初期化します。
  • 学習データの選択済み特徴量のみを使ってモデルを学習します。
  • テストデータの選択済み特徴量に基づいて予測します。
  • モデルの正解率、再現率、ROC/AUC スコアを出力します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Initialize the best model using parameters provided in description
model_best = DecisionTreeClassifier(____=____, ____=____, ____=____, random_state=42)

# Fit the model using only selected features from training set: done
model_best.fit(____, target_train)

# Make prediction based on selected list of features from test set
prediction_best = model_best.____(____)

# Print the general accuracy of the model_best
print(____.score(features_test_selected, target_test) * 100)

# Print the recall score of the model predictions
print(____(target_test, prediction_best) * 100)

# Print the ROC/AUC score of the model predictions
print(roc_auc_score(target_test, ____) * 100)
コードを編集して実行