Fitting the tree to employee data

A train/test split provides the opportunity to develop the classifier on the training component and test it on the rest of the dataset. In this exercise, you will start developing an employee turnover prediction model using the decision tree classification algorithm. The algorithm provides a .fit() method, which can be used to fit the features to the model in the training set.

Reminder: both target and features are already split into train and test components (Train: features_train, target_train, Test: features_test, target_test)

This exercise is part of the course

HR Analytics: Predicting Employee Churn in Python

View Course

Exercise instructions

  • Import the classification algorithm called DecisionTreeClassifier.
  • Initialize it as model and set the random state to 42.
  • Apply the decision tree model by fitting the training set features to the model.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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, ____)