計算準確度指標:Precision(精確率)
Precision(精確率)是用來衡量分類演算法準確性的重要指標。它定義為「真陽性佔真陽性與假陽性總和的比例」,也就是: $$\frac{\text{# 真陽性}}{\text{# 真陽性} + \text{# 假陽性}}.$$
- 真陽性(True Positives):實際離職且被正確分類為離職的人數。
- 假陽性(False Positives):實際留任但被誤分類為離職的人數。
若沒有假陽性,精確率等於 1。 若沒有真陽性,精確率等於 0。
在本練習中,你將使用 sklearn 的 precision_score 函式,計算我們初始分類模型的精確率。
變數 features_test 與 target_test 已提供在你的工作區中。
本練習屬於課程
HR 分析:用 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, ____)