كل المقررات

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

الفصل 2 (الجزء 2): End-to-End Machine Learning Project

Explore, prepare, train, tune and launch

في الجزء ده بنكمّل المشروع: استكشاف الداتا، تجهيزها بـ pipeline، تدريب ومقارنة نماذج، الضبط، وأخيراً الإطلاق والمراقبة.

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

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

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

أمثلة Python

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

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

المثال ١: تجهيز الداتا بـ ColumnTransformer

Sample output (press Run to produce your own):
[[-1.41 -0.98  0.    1.  ]
 [ 0.   -0.05  1.    0.  ]
 [ 0.   -0.61  0.    1.  ]
 [ 1.41  1.63  1.    0.  ]]
columns: ['num__rooms', 'num__area', 'cat__ocean_far', 'cat__ocean_near']

المثال ٢: خطأ التدريب مقابل cross-validation

Sample output (press Run to produce your own):
linear | train RMSE: 0.55 | CV RMSE: 0.97
tree | train RMSE: 0.0 | CV RMSE: 0.84

المثال ٣: Grid search

Sample output (press Run to produce your own):
max_depth 3 -> CV RMSE 0.717
max_depth 6 -> CV RMSE 0.685
max_depth 12 -> CV RMSE 0.734
best: {'max_depth': 6}

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

اختبار قصير

اختبر فهمك

1. Which is the correct order for preparing data safely?

2. One-hot encoding turns a text category into:

3. A decision tree shows near-zero training error. What should you check?

4. What does a pipeline give you?

5. When should the test set be used for the final check?

تمارين برمجة

جرّب بإيدك

التمرين 1

ابنِ pipeline فيه SimpleImputer(strategy='mean') ثم StandardScaler على مصفوفة فيها قيمة ناقصة، واطبع الناتج.

Build a pipeline of SimpleImputer(strategy='mean') then StandardScaler on an array with one missing value, and print the result.

(output appears here)

التمرين 2

جرّب Ridge بـ alpha = 0.1 و 1 و 10 على أول 4000 صف من الداتا واطبع CV RMSE لكل واحد (cv=5).

Try Ridge with alpha = 0.1, 1 and 10 on the first 4000 housing rows and print the CV RMSE for each (cv=5).

(output appears here)

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

Pipeline كامل: جهّز، درّب، وقارن

الداتا: Diabetes dataset (442 patients, 10 features). Source: Efron et al., 2004.

License / source: Ships with scikit-learn. Dataset page

الخطوات

  1. حمّل الداتا وقسّمها ٨٠/٢٠.
  2. اعمل Pipeline: StandardScaler ثم Ridge.
  3. اعمل Pipeline تاني: StandardScaler ثم RandomForestRegressor(n_estimators=100, random_state=0).
  4. احسب متوسط RMSE بـ 5-fold cross-validation للاتنين على الـ training.
  5. اختار الأحسن واقيسه مرة واحدة على الـ test.
Expected output (press Run to produce your own):
ridge cv RMSE: 55.9
forest cv RMSE: 59.0
chosen: ridge
test RMSE: 53.8

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

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

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