Machine Learning
البيانات والانحدار والتصنيف والتدريب وتقييم النماذج
🎯 Learning Objectives
- Understand the basic idea of Machine Learning.
- Distinguish supervised and unsupervised learning.
- Understand features, targets, training data, and test data.
- Derive the basic linear-regression model.
- Understand the mean-squared-error loss function.
- Explain training, validation, and testing.
- Understand overfitting and underfitting.
- Apply Machine Learning to load forecasting.
🎯 أهداف التعلم
- فهم الفكرة الأساسية للتعلم الآلي.
- التمييز بين التعلم الخاضع وغير الخاضع للإشراف.
- فهم الميزات والمتغير الهدف وبيانات التدريب والاختبار.
- اشتقاق نموذج الانحدار الخطي الأساسي.
- فهم دالة متوسط مربع الخطأ.
- فهم التدريب والتحقق والاختبار.
- فهم فرط المطابقة ونقص المطابقة.
- تطبيق التعلم الآلي على التنبؤ بالحمل الكهربائي.
1. What is Machine Learning?
Machine Learning is a branch of Artificial Intelligence in which a computer learns patterns and relationships from data.
1. ما هو التعلم الآلي؟
التعلم الآلي هو أحد فروع الذكاء الاصطناعي، حيث يتعلم الحاسوب الأنماط والعلاقات من البيانات.
2. Features and Target
In supervised learning, the input variables are called features, while the value to be predicted is called the target.
For load forecasting, the features may include temperature, hour, day type, and historical load.
2. الميزات والمتغير الهدف
في التعلم الخاضع للإشراف تسمى متغيرات الدخل بالميزات، بينما تسمى القيمة المطلوب التنبؤ بها بالمتغير الهدف.
في التنبؤ بالحمل يمكن أن تشمل الميزات درجة الحرارة والساعة ونوع اليوم والحمل التاريخي.
3. Supervised vs Unsupervised Learning
Training data contain inputs and known outputs.
Examples: regression and classification.
Training data contain inputs only, without known target values.
Example: clustering.
3. التعلم الخاضع وغير الخاضع للإشراف
تحتوي بيانات التدريب على المدخلات والقيم الصحيحة للمخرجات.
من أمثلته الانحدار والتصنيف.
تحتوي البيانات على المدخلات فقط دون وجود قيمة هدف معروفة.
من أمثلته التجميع Clustering.
4. Regression
Regression is used when the target is a continuous numerical value.
The simplest regression model is linear regression.
where:
- w = model weight or slope
- b = bias or intercept
- x = input
- ŷ = predicted output
4. الانحدار
يستخدم الانحدار عندما تكون القيمة الهدف قيمة عددية مستمرة.
أبسط نموذج للانحدار هو الانحدار الخطي:
5. Why Does Linear Regression Have This Form?
The equation of a straight line is:
In Machine Learning notation, we simply rename:
therefore:
5. لماذا يأخذ الانحدار الخطي هذه الصيغة؟
معادلة الخط المستقيم هي:
وفي التعلم الآلي نغيّر الرموز فقط:
فنحصل على:
6. Visual Meaning of Linear Regression
The blue points are measured data. The yellow line is the model.
6. المعنى الرسومي للانحدار الخطي
تمثل النقاط الزرقاء البيانات المقاسة، بينما يمثل الخط الأصفر النموذج الذي نحاول مطابقته مع البيانات.
7. Prediction Error
For each training example, the prediction error is:
If the prediction is exact:
7. خطأ التنبؤ
لكل مثال تدريب نحسب الفرق بين القيمة المتنبأ بها والقيمة الحقيقية:
إذا كان التنبؤ دقيقًا تمامًا فإن:
8. Mean Squared Error
We need one number that summarizes the errors of all training samples.
One common choice is Mean Squared Error:
Why square the errors?
- Positive and negative errors cannot cancel each other.
- Large errors receive a stronger penalty.
- The function is mathematically convenient for optimization.
8. متوسط مربع الخطأ
نحتاج إلى قيمة واحدة تلخص أخطاء جميع أمثلة التدريب.
إحدى أشهر الدوال هي متوسط مربع الخطأ:
لماذا نقوم بتربيع الخطأ؟
- حتى لا تلغي الأخطاء الموجبة الأخطاء السالبة.
- حتى نعطي الأخطاء الكبيرة عقوبة أكبر.
- لأن هذه الدالة مناسبة رياضيًا لعمليات التحسين.
9. Training as an Optimization Problem
Training means finding model parameters that minimize the loss.
9. التدريب كمسألة تحسين
يعني التدريب إيجاد قيم المعاملات التي تجعل دالة الخطأ أصغر ما يمكن.
10. A Simple Gradient Idea
The derivative tells us how the loss changes when a parameter changes.
If the derivative is positive, increasing w increases the loss. Therefore, we move w in the opposite direction.
where η is the learning rate.
10. فكرة بسيطة عن التدرج
يخبرنا الاشتقاق كيف تتغير دالة الخطأ عندما نغير أحد معاملات النموذج.
إذا كان الاشتقاق موجبًا فهذا يعني أن زيادة w ترفع الخطأ، ولذلك نتحرك في الاتجاه المعاكس.
حيث η هو معدل التعلم.
11. Classification
Classification is used when the target belongs to a category.
Healthy / Faulty
Normal / Warning / Emergency
11. التصنيف
يستخدم التصنيف عندما تكون القيمة المطلوبة فئة وليست قيمة عددية مستمرة.
سليم / معطّل
طبيعية / تحذير / طوارئ
12. Training, Validation, and Testing
Used to learn model parameters.
Used to tune model choices and hyperparameters.
Used for final unbiased performance evaluation.
12. التدريب والتحقق والاختبار
تستخدم لتعلم معاملات النموذج.
تستخدم لاختيار إعدادات النموذج المناسبة.
تستخدم لتقييم النموذج بعد انتهاء عملية التدريب.
13. Underfitting and Overfitting
The model is too simple and cannot capture the important relationship.
The model memorizes training data but performs poorly on new data.
13. نقص المطابقة وفرط المطابقة
النموذج بسيط جدًا ولا يستطيع تمثيل العلاقة الموجودة في البيانات.
يتعلم النموذج بيانات التدريب بصورة مفرطة لكنه يفشل مع بيانات جديدة.
14. Common Regression Metrics
| Metric | Equation | Meaning |
|---|---|---|
| MAE | (1/N) Σ |ŷᵢ-yᵢ| | Average absolute error |
| MSE | (1/N) Σ (ŷᵢ-yᵢ)² | Average squared error |
| RMSE | √MSE | Error in original physical units |
14. مقاييس شائعة لتقييم الانحدار
تستخدم MAE وMSE وRMSE لقياس الفرق بين القيم الحقيقية والمتنبأ بها.
15. Power-System Application: Load Forecasting
Suppose we want to predict electrical load for the next hour.
Possible input features:
Target:
15. تطبيق في نظم الطاقة: التنبؤ بالحمل
لنفترض أننا نريد التنبؤ بالحمل الكهربائي للساعة القادمة.
يمكن أن تكون المدخلات:
أما الهدف فهو:
16. Simple Load-Forecasting Example
Assume a simplified model using temperature only:
If:
then:
16. مثال مبسط للتنبؤ بالحمل
لنفترض استخدام نموذج مبسط يعتمد على درجة الحرارة فقط:
إذا كانت:
فإن:
17. Machine-Learning Workflow
17. خطوات مشروع التعلم الآلي
18. MATLAB Concept
A simple linear-regression model can be evaluated in MATLAB using:
The error can be calculated using:
and the mean-squared error:
Later, the MATLAB lab will update w and b iteratively.
18. الفكرة البرمجية في MATLAB
يمكن حساب خرج نموذج الانحدار الخطي في MATLAB من خلال:
ثم حساب الخطأ:
ثم متوسط مربع الخطأ:
19. Summary
- Machine Learning learns patterns from data.
- Features are inputs and targets are outputs to be predicted.
- Regression predicts continuous numerical values.
- Classification predicts categories.
- Linear regression has the form ŷ = wx + b.
- MSE measures prediction error.
- Training minimizes a loss function.
- Good models should generalize to unseen data.
- Load forecasting is an important power-system ML application.
19. الخلاصة
- يتعلم التعلم الآلي الأنماط من البيانات.
- الميزات هي المدخلات والهدف هو القيمة المطلوب التنبؤ بها.
- يستخدم الانحدار للتنبؤ بالقيم العددية المستمرة.
- يستخدم التصنيف للتنبؤ بالفئات.
- صيغة الانحدار الخطي هي ŷ = wx + b.
- يستخدم MSE لقياس خطأ التنبؤ.
- تهدف عملية التدريب إلى تصغير دالة الخطأ.
- يجب أن يعمل النموذج الجيد جيدًا مع بيانات لم يرها من قبل.
- يعد التنبؤ بالحمل من أهم تطبيقات التعلم الآلي في نظم الطاقة.
📝 Review Questions
- What is Machine Learning?
- What is the difference between a feature and a target?
- What is supervised learning?
- What is the difference between regression and classification?
- Explain the model ŷ = wx + b.
- Why do we square prediction errors in MSE?
- What is the purpose of training data?
- What is overfitting?
- How can Machine Learning be used for load forecasting?
📝 أسئلة المراجعة
- ما هو التعلم الآلي؟
- ما الفرق بين الميزة والمتغير الهدف؟
- ما المقصود بالتعلم الخاضع للإشراف؟
- ما الفرق بين الانحدار والتصنيف؟
- اشرح النموذج ŷ = wx + b.
- لماذا نقوم بتربيع الأخطاء في MSE؟
- ما وظيفة بيانات التدريب؟
- ما المقصود بفرط المطابقة؟
- كيف يمكن استخدام التعلم الآلي للتنبؤ بالحمل الكهربائي؟