การเปรียบเทียบตัวจำแนกประเภท
กรอบ ROI สามารถใช้กับตัวจำแนกประเภทต่าง ๆ เพื่อดูว่าค่า precision และ recall ที่สูงขึ้นส่งผลให้ ROI สูงขึ้นอย่างไร โปรดทราบว่าตัวจำแนกประเภท baseline ที่สร้างขึ้นจะมีผลตอบแทนรวมและต้นทุนรวมเป็น 0 เนื่องจาก tp และ fp จะเป็น 0 โดยออกแบบมาเช่นนั้น ในแบบฝึกหัดนี้ จะใช้กรอบ ROI เพื่อเปรียบเทียบตัวจำแนกประเภท logistic regression กับ decision tree
X_train, y_train, X_test, y_test พร้อมใช้งานใน workspace แล้ว รวมถึง pandas เป็น pd, numpy เป็น np และ LogisticRegression() จาก sklearn.linear_model ก็พร้อมใช้งานเช่นกัน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การพยากรณ์ CTR ด้วย Machine Learning ใน Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create and fit classifier
clf = ____
y_pred = clf.____(X_train, y_train).____(X_test)
# Calculate total return, total spent, and ROI
r, cost = 0.2, 0.05
tn, fp, fn, tp = ____(y_test, y_pred).____
total_return = ____ * r
total_spent = (____ + ____) * cost
roi = total_return / total_spent
print("Total return: %s, Total spent: %s, ROI: %s" %(total_return, total_spent, roi))