员工离职预测模型对比
在本练习中,您的任务是使用剪枝后的树(max_depth=7)对比均衡与不均衡(默认)模型。已为您计算了不均衡模型的 recall 和 ROC/AUC 分数。请为均衡模型完成相同步骤。
- 变量
features_train、target_train、features_test和target_test已在工作区中可用。 - 已为您拟合了一个不均衡模型,并将其预测结果保存为
prediction。 - 函数
recall_score()和roc_auc_score()已为您导入。
本练习是课程的一部分
HR Analytics:用 Python 预测员工流失
练习说明
- 初始化均衡模型,将最大深度设为
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(____)