โมเดลของคุณดีแค่ไหน?

Supervised Learning ด้วย scikit-learn

George Boorman

Core Curriculum Manager, DataCamp

เมตริกสำหรับการจำแนกประเภท

  • การวัดประสิทธิภาพโมเดลด้วยความแม่นยำ:

    • สัดส่วนของตัวอย่างที่จำแนกได้ถูกต้อง

    • ไม่ใช่เมตริกที่มีประโยชน์เสมอไป

Supervised Learning ด้วย scikit-learn

Class imbalance

  • การจำแนกประเภทเพื่อตรวจจับธุรกรรมธนาคารที่เป็นการฉ้อโกง

    • 99% ของธุรกรรมเป็นธุรกรรมปกติ และ 1% เป็นการฉ้อโกง
  • อาจสร้างตัวจำแนกที่ทำนายว่าไม่มีธุรกรรมใดเป็นการฉ้อโกงเลย

    • ความแม่นยำ 99%!

    • แต่ทำนายธุรกรรมฉ้อโกงได้แย่มาก

    • ล้มเหลวตามวัตถุประสงค์เดิม

  • Class imbalance: ความถี่ของแต่ละคลาสไม่เท่ากัน

  • ต้องใช้วิธีประเมินประสิทธิภาพแบบอื่น

Supervised Learning ด้วย scikit-learn

Confusion matrix สำหรับประเมินประสิทธิภาพการจำแนกประเภท

  • Confusion matrix

confusion_matrix.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

 

predicted_labels.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

 

actual_labels.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

 

confusion_matrix.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

 

true_positive.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

 

true_negative.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

 

false_negative.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

 

false_positive.png

Supervised Learning ด้วย scikit-learn

การประเมินประสิทธิภาพการจำแนกประเภท

confusion_matrix.png

  • ความแม่นยำ:

ch3_1_v3.030.png

Supervised Learning ด้วย scikit-learn

Precision

precision.png

  • Precision

precision_formula.png

  • Precision สูง = อัตรา false positive ต่ำ
  • Precision สูง: ธุรกรรมปกติถูกทำนายว่าเป็นการฉ้อโกงน้อยลง
Supervised Learning ด้วย scikit-learn

Recall

recall.png

  • Recall

recall_formula.png

  • Recall สูง = อัตรา false negative ต่ำ
  • Recall สูง: ทำนายธุรกรรมฉ้อโกงส่วนใหญ่ได้ถูกต้อง
Supervised Learning ด้วย scikit-learn

F1 score

  • F1 Score: $2 * \frac{precision \ * \ recall}{precision \ + \ recall}$
Supervised Learning ด้วย scikit-learn

Confusion matrix ใน scikit-learn

from sklearn.metrics import classification_report, confusion_matrix

knn = 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)
Supervised Learning ด้วย scikit-learn

Confusion matrix ใน scikit-learn

print(confusion_matrix(y_test, y_pred))
[[1106   11]
 [ 183   34]]
Supervised Learning ด้วย scikit-learn

Classification report ใน scikit-learn

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

มาฝึกกันเถอะ!

Supervised Learning ด้วย scikit-learn

Preparing Video For Download...