تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
قدّمت الوحدة السابقة النموذج التالي الذي أخطأ في تصنيف الكثير من
الأشجار في مجموعة الاختبار:
الشكل 16. النموذج المعقّد الذي يتسبب في حدوث مشاكل من الوحدة السابقة
يحتوي النموذج السابق على الكثير من الأشكال المعقّدة. هل يمكن أن يعالج نموذج
أبسط البيانات الجديدة بشكل أفضل؟ لنفترض أنّك استبدلت النموذج المعقّد بأحد نماذج الانحدار الخطي البسيطة جدًا، وهو خط مستقيم.
الشكل 17. نموذج أبسط بكثير
يُجري النموذج البسيط تعميمًا أفضل من النموذج المعقّد على البيانات الجديدة. وهذا يعني أنّه
قدّم النموذج البسيط تنبؤات أفضل في مجموعة الاختبار مقارنةً بالنموذج المعقّد.
لطالما كانت البساطة تفوق التعقيد. في الواقع، يعود استخدام المظهر البسيط إلى اليونان القديمة. بعد قرون، مثّل راهب من القرن الرابع عشر يدعى "ويليام الأوكامي" المفضّل لديه باستخدام فلسفة معروفة باسم سكين شارترخم. وتبقى هذه الفلسفة
مبدأ أساسيًا في العديد من العلوم، بما في ذلك
التعلم الآلي.
تمارين: التحقّق من فهمك
أنت بصدد تطوير معادلة فيزيائية. أيّ من الصِيَغ التالية
يتوافق بشكلٍ أكبر مع مبدأ "شفرات أوكام"؟
صيغة تحتوي على ثلاثة متغيّرات
إنّ استخدام ثلاثة متغيّرات أكثر ملاءمةً لمبدأ Ockham مقارنةً باستخدام اثني عشر متغيّرًا.
معادلة تحتوي على اثني عشر متغيّرًا
يبدو أنّ اثني عشر متغيّرًا معقدًا للغاية، أليس كذلك؟
إنّ معادلتَي الفيزياء الأكثر شهرة على الإطلاق (F=ma و
E=mc2) تتضمّنان كلّ منهما ثلاثة متغيّرات فقط.
أنت بصدد تنفيذ مشروع جديد تمامًا للتعلم الآلي، وعلي وشك اختيار
الميزات الأولى. كم عدد الميزات التي يجب اختيارها؟
اختَر من ميزة واحدة إلى ثلاث ميزات تبدو أنّها تتمتع بقدرة تنبؤية قوية.
من الأفضل أن تبدأ عملية جمع البيانات باستخدام ميزة واحدة أو
سمتَين فقط. سيساعدك ذلك في التأكّد من أنّ نموذج الذكاء الاصطناعي يعمل على النحو المطلوب.
بالإضافة إلى ذلك، عند إنشاء مرجع من ميزتَين،
ستشعر أنّك تحقّق تقدّمًا.
اختَر من 4 إلى 6 ميزات تبدو أنّها تتمتع بقدرة تنبؤية قوية.
قد تستخدم في النهاية هذا العدد من الميزات، ولكن من الأفضل
البدء بعدد أقل. وعادةً ما يعني عدد الميزات الأقل عددًا أقل من الصعوبات
غير الضرورية.
اختَر أكبر عدد ممكن من الميزات، حتى تتمكّن من مراقبة ميزات
التنبؤ الأقوى.
ابدأ بميزانية صغيرة. تضيف كل ميزة جديدة سمة جديدة إلى مجموعة بيانات
التدريب. عند زيادة الأبعاد، يزداد حجم المساحة
بسرعة كبيرة لدرجة أنّ بيانات التدريب المتاحة تصبح متفرقّة. كلما كانت بياناتك
أقل كثافة، كان من الصعب على النموذج تعلُّم العلاقة
بين السمات المهمة والعلامة. تُعرف هذه الظاهرة
باسم "لعنة الأبعاد".
التسوية
يجب أن تستوفي نماذج تعلُّم الآلة هدفَين متعارضَين في الوقت نفسه:
أن تلائم البيانات بشكل جيد
اضبط البيانات بأكبر قدر ممكن من البساطة.
من الطرق التي تحافظ على بساطة النموذج هي معاقبة النماذج المعقّدة، أي
فرض بساطة النموذج أثناء التدريب. إنّ فرض عقوبات على النماذج المعقدة
هو أحد أشكال التسويف.
الخسارة والتعقيد
حتى الآن، اقترحت هذه الدورة التدريبية أنّ الهدف الوحيد عند التدريب هو
تقليل الخسارة، أي:
$$\text{minimize(loss)}$$
كما رأيت، تميل النماذج التي تركّز فقط على تقليل الخسارة إلى التكيّف المفرط.
تعمل خوارزمية تحسين التدريب الأفضل على تقليل بعض المجموعات من
الخسارة والتعقيد:
$$\text{minimize(loss + complexity)}$$
لسوء الحظ، عادةً ما يكون معدّل الخسارة عكسيًا لمعدّل التعقيد. وكلما زادت الصعوبة، انخفضت الخسارة. وكلما انخفضت درجة التعقيد، زادت الخسارة.
من المفترض أن تعثر على حلّ وسط معقول يقدّم فيه النموذج تنبؤات جيدة
على كلّ من بيانات التدريب والبيانات الواقعية.
وهذا يعني أنّه يجب أن يجد نموذجك حلًا معقولاً
بين الخسارة والتعقيد.
ما هو التعقيد؟
لقد اطّلعت من قبل على بعض الطرق المختلفة لتحديد الخسارة. كيف
يمكنك قياس التعقيد؟ ابدأ استكشافك من خلال التمرين التالي:
التمرين: التحقّق من حدسك
حتى الآن، لم نوضّح بشكل كافٍ ما هو مستوى التعقيد
في الواقع. ما هي الأفكار التالية التي تعتقد أنّها مناسبة
لمقاييس التعقيد؟
يعتمد مستوى التعقيد على أوزان النموذج.
نعم، هذه إحدى الطرق لقياس تعقيد بعض النماذج.
يُعرف هذا المقياس باسم
تسوية L1.
يرتبط مستوى التعقيد بمربّع أوزان النموذج.
نعم، يمكنك قياس تعقيد بعض النماذج بهذه الطريقة. يُعرف هذا المقياس
باسم
تسوية 2.
التعقيد هو دالة لانحيازات جميع الميزات في
النموذج.
تاريخ التعديل الأخير: 2024-11-14 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2024-11-14 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eSimpler models often generalize better to new data than complex models, even if they perform slightly worse on training data.\u003c/p\u003e\n"],["\u003cp\u003eOccam's Razor favors simpler explanations and models, prioritizing them over more complex ones.\u003c/p\u003e\n"],["\u003cp\u003eRegularization techniques help prevent overfitting by penalizing model complexity during training.\u003c/p\u003e\n"],["\u003cp\u003eModel training aims to minimize both loss (errors on training data) and complexity for optimal performance on new data.\u003c/p\u003e\n"],["\u003cp\u003eModel complexity can be quantified using functions of model weights, like L1 and L2 regularization.\u003c/p\u003e\n"]]],[],null,["# Overfitting: Model complexity\n\nThe previous unit introduced the following model, which miscategorized a lot\nof trees in the test set:\n**Figure 16.** The misbehaving complex model from the previous unit.\n\nThe preceding model contains a lot of complex shapes. Would a simpler\nmodel handle new data better? Suppose you replace the complex model with\na ridiculously simple model--a straight line.\n**Figure 17.** A much simpler model.\n\nThe simple model generalizes better than the complex model on new data. That is,\nthe simple model made better predictions on the test set than the complex model.\n\nSimplicity has been beating complexity for a long time. In fact, the\npreference for simplicity dates back to ancient Greece. Centuries later,\na fourteenth-century friar named William of Occam formalized the preference\nfor simplicity in a philosophy known as [Occam's\nrazor](https://wikipedia.org/wiki/Occam%27s_razor). This philosophy\nremains an essential underlying principle of many sciences, including\nmachine learning.\n| **Note:** Complex models typically outperform simple models on the training set. However, simple models typically outperform complex models on the test set (which is more important).\n\n### Exercises: Check your understanding\n\nYou are developing a physics equation. Which of the following formulas conform more closely to Occam's Razor? \nA formula with three variables. \nThree variables is more Occam-friendly than twelve variables. \nA formula with twelve variables. \nTwelve variables seems overly complicated, doesn't it? The two most famous physics formulas of all time (F=ma and E=mc^2^) each involve only three variables. \nYou're on a brand-new machine learning project, about to select your first features. How many features should you pick? \nPick 1--3 features that seem to have strong predictive power. \nIt's best for your data collection pipeline to start with only one or two features. This will help you confirm that the ML model works as intended. Also, when you build a baseline from a couple of features, you'll feel like you're making progress! \nPick 4--6 features that seem to have strong predictive power. \nYou might eventually use this many features, but it's still better to start with fewer. Fewer features usually means fewer unnecessary complications. \nPick as many features as you can, so you can start observing which features have the strongest predictive power. \nStart smaller. Every new feature adds a new dimension to your training dataset. When the dimensionality increases, the volume of the space increases so fast that the available training data become sparse. The sparser your data, the harder it is for a model to learn the relationship between the features that actually matter and the label. This phenomenon is called \"the curse of dimensionality.\"\n\nRegularization\n--------------\n\nMachine learning models must simultaneously meet two conflicting goals:\n\n- Fit data well.\n- Fit data as simply as possible.\n\nOne approach to keeping a model simple is to penalize complex models; that is,\nto force the model to become simpler during training. Penalizing complex\nmodels is one form of **regularization**.\n| **A regularization analogy:** Suppose every student in a lecture hall had a little buzzer that emitted a sound that annoyed the professor. Students would press the buzzer whenever the professor's lecture became too complicated. Annoyed, the professor would be forced to simplify the lecture. The professor would complain, \"When I simplify, I'm not being precise enough.\" The students would counter with, \"The only goal is to explain it simply enough that I understand it.\" Gradually, the buzzers would train the professor to give an appropriately simple lecture, even if the simpler lecture isn't as sufficiently precise.\n\n### Loss and complexity\n\nSo far, this course has suggested that the only goal when training was to\nminimize loss; that is: \n$$\\\\text{minimize(loss)}$$\n\nAs you've seen, models focused solely on minimizing loss tend to overfit.\nA better training optimization algorithm minimizes some combination of\nloss and complexity: \n$$\\\\text{minimize(loss + complexity)}$$\n\nUnfortunately, loss and complexity are typically inversely related. As\ncomplexity increases, loss decreases. As complexity decreases, loss increases.\nYou should find a reasonable middle ground where the model makes good\npredictions on both the training data and real-world data.\nThat is, your model should find a reasonable compromise\nbetween loss and complexity.\n\nWhat is complexity?\n-------------------\n\nYou've already seen a few different ways of quantifying loss. How would\nyou quantify complexity? Start your exploration through the following exercise:\n\n### Exercise: Check your intuition\n\nSo far, we've been pretty vague about what *complexity* actually is. Which of the following ideas do you think would be reasonable complexity metrics? \nComplexity is a function of the model's weights. \nYes, this is one way to measure some models' complexity. This metric is called [**L~1~ regularization.**](/machine-learning/glossary#L1_regularization) \nComplexity is a function of the square of the model's weights. \nYes, you can measure some models' complexity this way. This metric is called [**L~2~ regularization**](/machine-learning/glossary#L2_regularization). \nComplexity is a function of the biases of all the features in the model. \nBias doesn't measure complexity.\n| **Key terms:**\n|\n| - [L~1~ regularization](/machine-learning/glossary#L1_regularization)\n| - [L~2~ regularization](/machine-learning/glossary#L2_regularization)\n- [Regularization](/machine-learning/glossary#regularization) \n[Help Center](https://support.google.com/machinelearningeducation)"]]