従業員データへの決定木の適合
学習用とテスト用に分割すると、学習データで分類器を作成し、残りのデータで評価できます。この演習では、decision tree 分類アルゴリズムを使って従業員の離職予測モデルの作成を始めます。アルゴリズムは .fit() メソッドを提供しており、学習用データの特徴量をモデルに当てはめることができます。
【リマインダー】目的変数と特徴量はすでに学習用とテスト用に分割済みです(Train: features_train, target_train、Test: features_test, target_test)。
この演習はコースの一部です
HRアナリティクス:Pythonで従業員離職を予測する
演習の手順
DecisionTreeClassifierという分類アルゴリズムをインポートします。- それを
modelとして初期化し、random_state を 42 に設定します。 - 学習用の特徴量を
modelに当てはめて、決定木モデルを適用します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import the classification algorithm
from sklearn.tree import ____
# Initialize it and call model by specifying the random_state parameter
model = ____(random_state=42)
# Apply a decision tree model to fit features to the target
model.____(features_train, ____)