كل المقررات

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

الفصل 9 (الجزء 2): Unsupervised Learning

Gaussian mixtures and anomaly detection

في الجزء الأخير هنشوف الـ Gaussian Mixture Models (GMM) وإزاي نختار عدد المكوّنات، وبعدين كشف الشذوذ Anomaly detection.

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

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

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

أمثلة Python

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

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

المثال ١: GMM بتدّي احتمالات

Sample output (press Run to produce your own):
weights: [0.33 0.33 0.33]
converged: True
probabilities of the first point: [[1. 0. 0.]]

المثال ٢: اختيار المكوّنات بالـ BIC

Sample output (press Run to produce your own):
components 1 | BIC 5653
components 2 | BIC 5308
components 3 | BIC 4606
components 4 | BIC 4637
components 5 | BIC 4676
components 6 | BIC 4706

المثال ٣: Isolation Forest

Sample output (press Run to produce your own):
flagged points: 4
the 3 planted outliers flagged: [-1, -1, -1]

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

اختبار قصير

اختبر فهمك

1. A GMM gives for each point:

2. For BIC, which model is preferred?

3. An anomaly is:

4. Isolation Forest flags points that are:

5. What does contamination control in IsolationForest?

تمارين برمجة

جرّب بإيدك

التمرين 1

على نفس بيانات المثال ٢ جرّب covariance_type = 'full' و 'diag' و 'spherical' بـ 3 مكوّنات واطبع الـ BIC.

On the data of example 2 try covariance_type = 'full', 'diag' and 'spherical' with 3 components and print the BIC.

(output appears here)

التمرين 2

في المثال ٣ غيّر contamination إلى 0.001 و 0.05 واطبع عدد النقط المعلّمة.

In example 3 change contamination to 0.001 and 0.05 and print the number of flagged points.

(output appears here)

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

دوّر على القراءات الشاذة في داتا السرطان

الداتا: 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. حمّل الداتا واعمل StandardScaler (من غير الـ labels).
  2. درّب IsolationForest(contamination=0.05, random_state=0).
  3. اطبع عدد العينات المعلّمة كشاذة.
  4. احسب نسبة العينات الخبيثة (target==0) بين الشاذة وبين الباقي.
  5. اشرح: هل الشاذ بالضرورة خبيث؟
Expected output (press Run to produce your own):
flagged: 29 of 569
malignant share among flagged: 0.9
malignant share among the rest: 0.34

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

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

ملف 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.