انتظام Ridge وLasso
الحد من فرط الملاءمة باستخدام العقوبات
انتظام Ridge وLasso درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
When a Line Overfits
Plain linear regression can chase noise, growing huge coefficients that fit training data yet fail on new data. That trap is called overfitting. 😬
Add a Penalty
Regularization fixes this by adding a penalty for large coefficients. The model now balances fitting the data against keeping weights small.
Ridge Shrinks Weights
Ridge penalizes the squared size of the coefficients. It pulls every weight toward zero but rarely makes any exactly zero.
from sklearn.linear_model import Ridge
model = Ridge(alpha=1.0).fit(X, y)Lasso Can Zero Them Out
Lasso penalizes the absolute size instead. This can drive weak coefficients all the way to zero, dropping those features entirely.
from sklearn.linear_model import Lasso
model = Lasso(alpha=0.1).fit(X, y)Lasso Selects Features
Because Lasso zeroes weak weights, it doubles as feature selection. The surviving non-zero coefficients are the ones it found useful.
Alpha Sets the Strength
The alpha knob controls how hard the penalty pushes. Bigger alpha means stronger shrinkage and a simpler, smoother model.
Too Much Alpha Underfits
Crank alpha too high and coefficients shrink so far the model ignores real signal. That opposite mistake is called underfitting.
Scale Before You Penalize
Penalties compare coefficients directly, so features must share a scale first. Standardize your data or the penalty hits big-unit features unfairly.
from sklearn.preprocessing import StandardScalerRidge or Lasso?
Use Ridge when most features help a little, and Lasso when you suspect many are useless and want a sparse, lean model.
ElasticNet Blends Both
Can't decide? ElasticNet mixes the Ridge and Lasso penalties, giving you shrinkage and some feature dropping at the same time.
from sklearn.linear_model import ElasticNetTune With Cross-Validation
Never guess alpha by hand. Try a range and pick the value that scores best on held-out folds with cross-validation.
from sklearn.linear_model import RidgeCVQuick Check
One key difference sets these two apart in practice.
Recap
Regularization tames overfitting: Ridge shrinks weights, Lasso can zero them, and alpha sets the strength. Scale first, then tune. 🎯
الأسئلة الشائعة
هل درس «انتظام Ridge وLasso» مجاني؟
نعم — نص درس «انتظام Ridge وLasso» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «انتظام Ridge وLasso»؟
الحد من فرط الملاءمة باستخدام العقوبات تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «انتظام Ridge وLasso»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- مراجعة الانحدار الخطي
- انتظام Ridge وLasso
- انحدار شجرة القرار
- الغابة العشوائية للانحدار