Supervised Learning ด้วย scikit-learn
George Boorman
Core Curriculum Manager, DataCamp
การวัดประสิทธิภาพโมเดลด้วยความแม่นยำ:
สัดส่วนของตัวอย่างที่จำแนกได้ถูกต้อง
ไม่ใช่เมตริกที่มีประโยชน์เสมอไป
การจำแนกประเภทเพื่อตรวจจับธุรกรรมธนาคารที่เป็นการฉ้อโกง
อาจสร้างตัวจำแนกที่ทำนายว่าไม่มีธุรกรรมใดเป็นการฉ้อโกงเลย
ความแม่นยำ 99%!
แต่ทำนายธุรกรรมฉ้อโกงได้แย่มาก
ล้มเหลวตามวัตถุประสงค์เดิม
Class imbalance: ความถี่ของแต่ละคลาสไม่เท่ากัน
ต้องใช้วิธีประเมินประสิทธิภาพแบบอื่น














from sklearn.metrics import classification_report, confusion_matrixknn = KNeighborsClassifier(n_neighbors=7)X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=42)knn.fit(X_train, y_train)y_pred = knn.predict(X_test)
print(confusion_matrix(y_test, y_pred))
[[1106 11]
[ 183 34]]
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 0.86 0.99 0.92 1117
1 0.76 0.16 0.26 217
accuracy 0.85 1334
macro avg 0.81 0.57 0.59 1334
weighted avg 0.84 0.85 0.81 1334
Supervised Learning ด้วย scikit-learn