การคำนวณเมตริกความแม่นยำ: Precision
Precision score เป็นเมตริกสำคัญที่ใช้วัดความแม่นยำของอัลกอริทึมการจำแนกประเภท โดยคำนวณจาก สัดส่วนของ True Positives ต่อผลรวมของ True Positives และ False Positives หรือ $$\frac{\text{# of True Positives}}{\text{# of True Positives} + \text{# of False Positives}}.$$
- True Positives หมายถึงจำนวนพนักงานที่ลาออกจริง และโมเดลทำนายได้ถูกต้องว่าจะลาออก
- False Positives หมายถึงจำนวนพนักงานที่อยู่ต่อจริง แต่โมเดลทำนายผิดว่าจะลาออก
หากไม่มี False Positives เลย Precision score จะเท่ากับ 1 หากไม่มี True Positives เลย Precision score จะเท่ากับ 0
ในแบบฝึกหัดนี้ เราจะคำนวณ Precision score (โดยใช้ฟังก์ชัน precision_score จาก sklearn) สำหรับโมเดลการจำแนกประเภทเริ่มต้นของเรา
ตัวแปร features_test และ target_test พร้อมใช้งานอยู่ใน workspace แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
HR Analytics: การพยากรณ์การลาออกของพนักงานด้วย Python
คำแนะนำการฝึกหัด
- Import ฟังก์ชัน
precision_scoreจากโมดูลsklearn.metrics - ใช้โมเดลเริ่มต้นพยากรณ์การลาออก (โดยอิงจาก features ของชุดทดสอบ)
- คำนวณ 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, ____)