با مجموعهها، منظم بمانید ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
واحد قبلی مدل زیر را معرفی کرد که بسیاری از درختان را در مجموعه آزمایشی به اشتباه دسته بندی کرد:
شکل 16. مدل پیچیده بد رفتار از واحد قبلی.
مدل قبلی شامل بسیاری از اشکال پیچیده است. آیا یک مدل ساده تر داده های جدید را بهتر مدیریت می کند؟ فرض کنید مدل پیچیده را با یک مدل ساده مضحک جایگزین کرده اید - یک خط مستقیم.
شکل 17. یک مدل بسیار ساده تر.
مدل ساده در داده های جدید بهتر از مدل پیچیده تعمیم می یابد. یعنی مدل ساده پیشبینیهای بهتری در مجموعه آزمایشی نسبت به مدل پیچیده داشت.
مدت هاست که سادگی بر پیچیدگی غلبه کرده است. در واقع، ترجیح سادگی به یونان باستان برمی گردد. قرنها بعد، یک راهب قرن چهاردهمی به نام ویلیام اوکام ترجیح سادگی را در فلسفهای به نام تیغ اوکام رسمیت داد. این فلسفه یک اصل اساسی اساسی بسیاری از علوم، از جمله یادگیری ماشینی است.
تمرینات: درک خود را بررسی کنید
شما در حال توسعه یک معادله فیزیک هستید. کدام یک از فرمول های زیر با تیغ Occam بیشتر مطابقت دارد؟
فرمولی با سه متغیر
سه متغیر نسبت به دوازده متغیر سازگارتر است.
فرمولی با دوازده متغیر.
دوازده متغیر بیش از حد پیچیده به نظر می رسند، اینطور نیست؟ دو فرمول فیزیک معروف تمام دوران (F=ma و E=mc 2 ) هر کدام فقط شامل سه متغیر هستند.
شما در یک پروژه یادگیری ماشینی کاملاً جدید هستید و در شرف انتخاب اولین ویژگی های خود هستید. چند ویژگی را باید انتخاب کنید؟
1 تا 3 ویژگی را انتخاب کنید که به نظر می رسد قدرت پیش بینی قوی دارند.
بهتر است خط لوله جمع آوری داده های شما فقط با یک یا دو ویژگی شروع شود. این به شما کمک می کند تا تأیید کنید که مدل ML همانطور که در نظر گرفته شده است کار می کند. همچنین، هنگامی که از چند ویژگی یک خط پایه ایجاد می کنید، احساس می کنید در حال پیشرفت هستید!
4 تا 6 ویژگی را انتخاب کنید که به نظر می رسد قدرت پیش بینی قوی دارند.
ممکن است در نهایت از این تعداد ویژگی استفاده کنید، اما بهتر است با کمتر شروع کنید. ویژگی های کمتر معمولاً به معنای کمتر شدن عوارض غیر ضروری است.
تا جایی که می توانید ویژگی ها را انتخاب کنید تا بتوانید مشاهده کنید کدام ویژگی قوی ترین قدرت پیش بینی را دارد.
کوچکتر شروع کنید. هر ویژگی جدید بعد جدیدی به مجموعه داده آموزشی شما اضافه می کند. وقتی ابعاد افزایش می یابد، حجم فضا آنقدر سریع افزایش می یابد که داده های آموزشی موجود پراکنده می شوند. هرچه دادههای شما کمتر باشد، یادگیری رابطه بین ویژگیهایی که واقعاً مهم هستند و برچسب برای یک مدل دشوارتر است. این پدیده "نفرین ابعاد" نامیده می شود.
منظم سازی
مدل های یادگیری ماشین باید به طور همزمان دو هدف متناقض را برآورده کنند:
داده ها را به خوبی تنظیم کنید.
داده ها را به ساده ترین شکل ممکن جاسازی کنید.
یک رویکرد برای ساده نگه داشتن یک مدل، جریمه کردن مدل های پیچیده است. یعنی مدل را مجبور کنیم در طول آموزش ساده تر شود. جریمه کردن مدل های پیچیده یکی از اشکال منظم سازی است.
از دست دادن و پیچیدگی
تا کنون، این دوره پیشنهاد کرده است که تنها هدف در هنگام آموزش، به حداقل رساندن ضرر است. یعنی:
$$\text{minimize(loss)}$$
همانطور که مشاهده کردید، مدل هایی که صرفاً بر روی به حداقل رساندن ضرر تمرکز دارند، بیش از حد مناسب هستند. یک الگوریتم بهینه سازی آموزش بهتر ترکیبی از ضرر و پیچیدگی را به حداقل می رساند:
$$\text{minimize(loss + complexity)}$$
متأسفانه، از دست دادن و پیچیدگی معمولاً رابطه معکوس دارند. با افزایش پیچیدگی، ضرر کاهش می یابد. با کاهش پیچیدگی، ضرر افزایش می یابد. شما باید یک حد وسط معقول پیدا کنید که در آن مدل، هم در مورد داده های آموزشی و هم در داده های دنیای واقعی پیش بینی های خوبی انجام دهد. یعنی مدل شما باید یک سازش معقول بین ضرر و پیچیدگی پیدا کند.
پیچیدگی چیست؟
شما قبلاً چند روش مختلف برای تعیین مقدار ضرر دیده اید. چگونه پیچیدگی را کمیت می کنید؟ کاوش خود را از طریق تمرین زیر شروع کنید:
ورزش: شهود خود را بررسی کنید
تا کنون، در مورد اینکه پیچیدگی در واقع چیست، بسیار مبهم بوده ایم. به نظر شما کدام یک از ایده های زیر معیارهای پیچیدگی معقول هستند؟
تاریخ آخرین بهروزرسانی 2024-11-07 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2024-11-07 بهوقت ساعت هماهنگ جهانی."],[[["\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)"]]