将决策树拟合到员工数据
通过训练/测试集划分,您可以在训练集上开发分类器,并在数据集的其余部分进行测试。在本练习中,您将开始使用决策树分类算法来构建员工流失预测模型。该算法提供 .fit() 方法,可用于在训练集中将特征拟合到模型。
提醒:目标变量与特征变量已按训练集与测试集拆分(Train:features_train、target_train,Test:features_test、target_test)。
本练习是课程的一部分
HR Analytics:用 Python 预测员工流失
练习说明
- 导入名为
DecisionTreeClassifier的分类算法。 - 将其初始化为
model,并将随机种子设为 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, ____)