计算准确性指标:精确率(Precision)
精确率(Precision)是衡量分类算法准确性的重要指标。其计算方式为:真正例数占真正例与假正例之和的比例,即: $$\frac{\text{# of True Positives}}{\text{# of True Positives} + \text{# of False Positives}}.$$
- 在本课程中,真正例(True Positives) 指实际离职且被正确预测为离职的员工数量;
- 假正例(False Positives) 指实际未离职但被错误预测为离职的员工数量。
若没有假正例,精确率为 1。 若没有真正例,精确率为 0。
在本练习中,您将使用 sklearn 的 precision_score 函数来计算我们初始分类模型的精确率。
变量 features_test 与 target_test 已在您的工作区中提供。
本练习是课程的一部分
HR Analytics:用 Python 预测员工流失
练习说明
- 从模块
sklearn.metrics导入函数precision_score。 - 使用初始模型基于测试集的特征预测离职情况。
- 通过将
target_test与测试集预测结果进行比较来计算精确率。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the function to calculate precision score
from sklearn.____ import ____
# Predict whether employees will churn using the test set
prediction = model.____(features_test)
# Calculate precision score by comparing target_test with the prediction
____(target_test, ____)