كل المقررات

الرئيسية / مقرر Machine Learning / الفصل 3 الجزء 2

الفصل 3 (الجزء 2): Classification

Thresholds, ROC, multiclass, error analysis

في الجزء ده بنكمّل التصنيف: ضبط الـ threshold، منحنى ROC، التصنيف لأكتر من فئتين، تحليل الأخطاء، وmultilabel.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

أمثلة Python

أمثلة صغيرة بالـ scikit-learn

الكود والنتيجة معروضين هنا كنص ثابت (النتائج اتجرّبت فعلاً). لتشغيل الكود بنفسك انسخه في Google Colab المجاني. تقدر كمان تفتح الدفتر الرسمي للكتاب (ترخيص Apache-2.0) من الرابط تحت.

المثال ١: تحريك الـ threshold

Sample output (press Run to produce your own):
threshold -2000 | precision: 0.36 | recall: 0.98
threshold 0 | precision: 0.98 | recall: 0.91
threshold 500 | precision: 1.0 | recall: 0.8

المثال ٢: ROC AUC

Sample output (press Run to produce your own):
ROC AUC: 0.995

المثال ٣: أرقام ٠ إلى ٩ وتحليل الأخطاء

Sample output (press Run to produce your own):
accuracy: 0.939
most common mistake: true 1 predicted as 8 - 10 times

افتح الدفتر الرسمي في Colab

اختبار قصير

اختبر فهمك

1. Raising the decision threshold usually:

2. An AUC of 0.5 means:

3. A medical screening test should lean towards:

4. One-versus-rest with 10 classes trains:

5. Error analysis starts with:

تمارين برمجة

جرّب بإيدك

التمرين 1

للـ «هل الرقم ٥؟»: من القيم [-2000, -1000, 0, 500, 1000] دوّر على أصغر threshold يدّي precision ≥ 0.95 واطبعه مع الـ recall.

For 'is it 5?': from the thresholds [-2000, -1000, 0, 500, 1000], find the smallest one with precision >= 0.95 and print it with its recall.

(output appears here)

التمرين 2

درّب KNeighborsClassifier(n_neighbors=3) على الأرقام العشرة واطبع دقته، وقارنها بدقة SGD (٠.٩٣٩).

Train KNeighborsClassifier(n_neighbors=3) on all ten digits, print its accuracy, and compare it with SGD (0.939).

(output appears here)

مشروع صغير في آخر المحاضرة

اختار الـ threshold حسب التكلفة

الداتا: Breast Cancer Wisconsin (Diagnostic): 569 samples, 30 features. Source: UCI.

License / source: Ships with scikit-learn; open data from the UCI repository. Dataset page

الخطوات

  1. حمّل الداتا وخلّي الفئة 'خبيث' هي الإيجابية (target==0).
  2. قسّم ٧٠/٣٠ بـ stratify ودرّب LogisticRegression داخل Pipeline مع StandardScaler.
  3. هات الاحتمالات بـ predict_proba.
  4. جرّب thresholds 0.2 و 0.5 و 0.8 واطبع precision و recall لكل واحد.
  5. اختار threshold للفحص الطبي (recall عالي) واشرح اختيارك.
Expected output (press Run to produce your own):
threshold 0.2 precision 0.955 recall 0.984
threshold 0.5 precision 0.984 recall 0.938
threshold 0.8 precision 1.0 recall 0.875

مشروع نهاية الفصل

ملف المشروع العملي للفصل 3

ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.

افتح ملف المشروع (PDF)

Credits: topic order follows the public chapter list of Aurélien Géron's book "Hands-On Machine Learning with Scikit-Learn, Keras and TensorFlow" (3rd ed.). All explanations and code here are original.