كل المقررات

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

الفصل 1 (الجزء 2): The Machine Learning Landscape

Batch and online, instance and model based, challenges, testing

في الجزء ده هنكمّل: التعلّم Batch وOnline، الفرق بين Instance-based وModel-based، أهم مشكلات الـ ML، وإزاي نختبر النموذج صح.

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

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

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

أمثلة Python

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

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

المثال ١: Instance-based مقابل Model-based

Sample output (press Run to produce your own):
instance-based prediction at x=4: 16.9
model-based prediction at x=4:    17.2
learned formula: y = 3.05 * x + 5.05

المثال ٢: شوف الـ Overfitting بعينك

Sample output (press Run to produce your own):
degree 1 | train R2: 0.04 | test R2: -0.11
degree 2 | train R2: 0.93 | test R2: 0.71
degree 9 | train R2: 0.97 | test R2: 0.16

المثال ٣: Cross-validation ومرة واحدة على الـ test

Sample output (press Run to produce your own):
k = 1 -> validation accuracy: 0.942
k = 5 -> validation accuracy: 0.933
k = 15 -> validation accuracy: 0.958
k = 50 -> validation accuracy: 0.925
final test accuracy (used once): 0.967

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

اختبار قصير

اختبر فهمك

1. A system that updates itself little by little as new data streams in uses:

2. A model that stores the training examples and compares new cases to similar ones is:

3. High score on training data but low score on new data signals:

4. Which of these usually helps against overfitting?

5. What should the test set be used for?

تمارين برمجة

جرّب بإيدك

التمرين 1

في مثال الـ overfitting أضف degree 3 و 5 للجدول واكتب ملاحظتك: متى بدأ الفرق بين train و test يكبر؟

In the overfitting example, add degrees 3 and 5 to the table and note when the train/test gap starts to grow.

(output appears here)

التمرين 2

استخدم cross_val_score بـ cv=10 لتجربة k = 3, 25, 50 على بيانات iris واطبع أحسن k.

Use cross_val_score with cv=10 to try k = 3, 25, 50 on iris and print the best k.

(output appears here)

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

ابحث عن أحسن k وما تغشّش في الـ test

الداتا: Optical Recognition of Handwritten Digits: 1,797 images of 8x8 pixels, 10 classes. Original source: UCI.

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

الخطوات

  1. حمّل digits وقسّمه training و test (٢٠٪ test).
  2. جرّب k = 1, 3, 5, 9, 15 بالـ cross_val_score (cv=5) على الـ training بس.
  3. اختار أحسن k من نتايج الـ cross-validation.
  4. درّب بالـ k ده على كل الـ training واقيس مرة واحدة على الـ test.
  5. اكتب جملة: ليه ما اخترناش k بالنظر للـ test؟
Expected output (press Run to produce your own):
k = 1 cv accuracy = 0.987
k = 3 cv accuracy = 0.987
k = 5 cv accuracy = 0.983
k = 9 cv accuracy = 0.982
k = 15 cv accuracy = 0.974
best k: 3
test accuracy: 0.986

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

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

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