كل المقررات

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

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

Framing the problem, metrics, getting data, and the test set

في الجزء ده بنبدأ مشروع ML كامل: تحديد المشكلة، اختيار مقياس الأداء، تحميل الداتا والنظر فيها، وإنشاء الـ test set بالطريقة الصح.

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

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

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

أمثلة Python

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

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

المثال ١: RMSE و MAE

Sample output (press Run to produce your own):
RMSE by hand: 134.7 | MAE by hand: 70.0
RMSE sklearn: 134.7 | MAE sklearn: 70.0

المثال ٢: نظرة سريعة على الداتا

Sample output (press Run to produce your own):
(20640, 9)
['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude', 'MedHouseVal']
count    20640.00
mean         3.87
std          1.90
min          0.50
25%          2.56
50%          3.53
75%          4.74
max         15.00
Name: MedInc, dtype: float64

المثال ٣: random مقابل stratified

Sample output (press Run to produce your own):
            overall  random  stratified
income_cat                             
1             0.040   0.040       0.040
2             0.319   0.324       0.319
3             0.351   0.359       0.351
4             0.176   0.167       0.176
5             0.114   0.109       0.114

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

اختبار قصير

اختبر فهمك

1. Predicting a house price (a number) from labelled examples is:

2. Which measure punishes large errors more strongly?

3. Why set the test set aside early?

4. What does a stratified split keep?

5. What do head(), info() and describe() help with?

تمارين برمجة

جرّب بإيدك

التمرين 1

احسب RMSE و MAE بنفسك بـ numpy للقيم الفعلية [3, 5, 2, 7] والمتوقعة [2, 5, 4, 8].

Compute RMSE and MAE with numpy for actual [3, 5, 2, 7] and predicted [2, 5, 4, 8].

(output appears here)

التمرين 2

حمّل داتا California housing، اطبع المتوسط لعمود MedHouseVal، ثم قسّمها 80/20 بـ random_state=42 واطبع حجم الـ train والـ test.

Load California housing, print the mean of MedHouseVal, then split 80/20 with random_state=42 and print the train and test sizes.

(output appears here)

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

قسّم الداتا صح وحدّد الـ baseline

الداتا: Diabetes dataset: 442 patients, 10 baseline features, target = disease progression after one year. Source: Efron, Hastie, Johnstone, Tibshirani (Least Angle Regression, 2004).

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

الخطوات

  1. حمّل الداتا واطبع شكلها وأول قيم للـ target.
  2. قسّم ٨٠٪ تدريب و٢٠٪ اختبار بـ random_state=42.
  3. احسب RMSE لـ baseline بيتوقّع متوسط الـ training دايماً.
  4. درّب LinearRegression واحسب RMSE على الـ test.
  5. قارن الرقمين: النموذج أحسن من الـ baseline بكام؟
Expected output (press Run to produce your own):
baseline RMSE: 73.2
linear regression RMSE: 53.9

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.