الـ Linear Regression: الـ Model والـ Cost Function والحل المباشر
الـ linear regression بيتوقع قيمة كمجموع موزون للـ features زائد bias، والتدريب بيدور على الـ parameters اللي بتقلل الـ mean squared error.
الـ model هو y-hat = theta0 + theta1 x1 + ... + thetan xn، حيث n عدد الـ features وxi قيمة الـ feature رقم i وthetaj الـ parameter رقم j (و theta0 هو الـ bias). بالشكل الـ vectorized: y-hat = h(x) = theta . x، والـ h هي الـ hypothesis يعني دالة التوقع.
التدريب معناه ضبط الـ parameters عشان الـ model يتماشى مع الـ training set أحسن ما يمكن. محتاجين نلاقي theta اللي بتقلل الـ cost function. عمليًا أسهل نقلل الـ mean squared error (MSE) من الـ RMSE، والاتنين بيدّوا نفس الـ theta لأن الجذر التربيعي دالة متزايدة. والـ MSE للـ linear regression convex.
فيه طريقتين للتدريب: معادلة closed-form (normal equation) بتحسب الـ parameters مباشرة، أو optimization تكراري بالـ gradient descent. الـ LinearRegression في Scikit-Learn بيستخدم SVD لحساب الـ pseudoinverse وده حوالي O(n²) في عدد الـ features وأكفأ من الـ normal equation وبيتعامل مع الحالات الصعبة. الاتنين بيبطّأوا لو الـ features كتير أوي، وهنا الـ gradient descent أفضل.
أهم النقاط
- y-hat = theta . x مع bias اسمه theta0.
- نقلل الـ MSE (نفس نتيجة تقليل الـ RMSE).
- closed form (normal equation أو SVD pseudoinverse) مقابل gradient descent.
- الـ SVD في LinearRegression حوالي O(n²) في عدد الـ features.
- الـ MSE convex: فيه global minimum واحد.
مثال محلول
نفرض y = theta0 + theta1 x على النقط (1,2) و(2,4) و(3,6). حل الـ least-squares هو theta0 = 0 وtheta1 = 2، فتوقع x = 4 هو 8 والـ MSE = 0.
أسئلة شائعة
ليه بنقلل الـ MSE مش الـ RMSE؟
لأن theta اللي بتقلل الـ MSE هي نفسها اللي بتقلل الـ RMSE، والـ MSE أسهل في الاشتقاق.
هل الـ linear regression محتاج gradient descent؟
مش دايمًا. الحل closed-form بيحسب الـ parameters مباشرة، بس الـ gradient descent بيتحمل عدد features ضخم أحسن.
أسئلة تدريب على الموضوع ده
جرّبها بنفسك، وبعدين افتح التطبيق وشوف الإجابة والشرح.
- If we train a Linear Regression model on the California housing data (book example), it underfits the training data.
- A. true
- B. false
- For a convex cost function such as the MSE of Linear Regression, in Gradient Descent, once the gradient is.......... you have reached a minimum.
- A. zero
- B. one
- C. three
- D. None of them
- To train linear regression model, use closed-form that directly computes the model parameters
- A. true
- B. false
- For the convex MSE cost of Linear Regression, GD is guaranteed to approach arbitrarily close the global minimum (if you wait long enough and the learning rate is not too high).
- A. true
- B. false
- yˆ = hθ(x) = θ.x in Linear Regression Model Prediction (Vectorized Form), hθ is refer to the............
- A. model’s parameter vector.
- B. instance’s feature vector.
- C. hypothesis function.
- D. None of them
- Linear Regression is a polynomial model that makes a prediction by simply computing a weighted sum of the input features
- A. true
- B. false
مواضيع مرتبطة
- الـ Gradient Descent: Batch وStochastic وMini-batch
- الـ Regularization والـ Ridge Regression
- يعني إيه Machine Learning؟
- الفرق بين Supervised و Unsupervised و Semi-supervised و Reinforcement Learning
- الـ Overfitting والـ Underfitting في الماشين ليرنينج
- الفرق بين Batch Learning و Online Learning
- كل المواضيع: الماشين ليرنينج
بصمجلي مشروع طلابي مستقل، مش موقع رسمي لجامعة الدلتا. ارجع لمحاضراتك ودكتورك دايمًا.