위의 모델에는 많은 복잡한 도형이 포함되어 있습니다. 더 간단한 모델이 새 데이터를 더 잘 처리하나요? 복잡한 모델을 지극히 단순한 모델(직선)로 대체한다고 가정해 보겠습니다.
그림 17. 훨씬 간단한 모델입니다.
간단한 모델이 복잡한 모델보다 새 데이터에 대해 더 잘 일반화됩니다. 즉, 단순한 모델이 복잡한 모델보다 테스트 세트에서 더 나은 예측을 내렸습니다.
단순성은 오랫동안 복잡성을 이기고 있습니다. 사실 단순함에 대한 선호는 고대 그리스로 거슬러 올라갑니다. 수세기 후, 14세기의 수도사인 윌리엄 오컴은 오컴의 면도날이라는 철학으로 단순성에 대한 선호를 공식화했습니다. 이 철학은 머신러닝을 비롯한 여러 과학의 근본 원칙으로 남아 있습니다.
연습문제: 이해도 확인
물리 방정식을 개발하고 있습니다. 다음 공식 중 오캄의 면도날에 더 근접한 것은 무엇인가요?
세 개의 변수가 있는 수식
12개 변수보다 3개 변수가 오캄의 면도날 원리에 더 적합합니다.
12개의 변수가 있는 수식
12개의 변수가 너무 복잡해 보이지 않나요? 역대 가장 유명한 두 가지 물리학 공식 (F=ma 및 E=mc2)에는 각각 세 개의 변수만 포함됩니다.
새 머신러닝 프로젝트를 진행 중이며 첫 번째 기능을 선택하려고 합니다. 얼마나 많은 지형지물을 선택해야 하나요?
예측력이 강한 것으로 보이는 특성 1~3개를 선택합니다.
데이터 수집 파이프라인은 하나 또는 두 개의 기능으로 시작하는 것이 가장 좋습니다. 이렇게 하면 ML 모델이 의도한 대로 작동하는지 확인할 수 있습니다. 또한 몇 가지 기능으로 기준선을 빌드하면 진행 중이라는 느낌을 받을 수 있습니다.
예측력이 강한 것으로 보이는 특성 4~6개를 선택합니다.
나중에 이 정도의 기능을 사용하게 되겠지만, 처음에는 적은 수의 기능으로 시작하는 것이 좋습니다. 기능이 적을수록 일반적으로 불필요한 정보 표시가 줄어듭니다.
예측력이 가장 강한 특성을 관찰할 수 있도록 최대한 많은 특성을 선택합니다.
소규모로 시작합니다. 새로운 기능을 추가할 때마다 학습 데이터 세트에 새로운 차원이 추가됩니다. 차원이 증가하면 공간의 볼륨이 너무 빨리 증가하여 사용 가능한 학습 데이터가 희박해집니다. 데이터가 희박할수록 모델이 실제로 중요한 특성과 라벨 간의 관계를 학습하기가 더 어려워집니다. 이 현상을 '차원 저주'라고 합니다.
정규화
머신러닝 모델은 다음과 같이 상반된 두 가지 목표를 동시에 충족해야 합니다.
데이터에 잘 맞습니다.
데이터를 최대한 간단하게 맞춥니다.
모델을 단순하게 유지하는 한 가지 방법은 복잡한 모델에 페널티를 적용하는 것입니다. 즉, 학습 중에 모델이 더 단순해지도록 강제하는 것입니다. 복잡한 모델에 불이익을 주는 것은 정규화의 한 형태입니다.
손실 및 복잡성
지금까지 이 과정에서는 학습의 유일한 목표는 손실을 최소화하는 것이라고 제안했습니다. 즉,
$$\text{minimize(loss)}$$
보시다시피 손실 최소화에만 초점을 맞춘 모델은 오버핏되는 경향이 있습니다. 더 나은 학습 최적화 알고리즘은 손실과 복잡성의 조합을 최소화합니다.
$$\text{minimize(loss + complexity)}$$
안타깝게도 손실과 복잡성은 일반적으로 반비례합니다. 복잡성이 증가하면 손실이 감소합니다. 복잡성이 감소하면 손실이 증가합니다. 모델이 학습 데이터와 실제 데이터 모두에서 좋은 예측을 하는 적절한 중간점을 찾아야 합니다. 즉, 모델은 손실과 복잡도 간에 적절한 타협점을 찾아야 합니다.
복잡성이란 무엇인가요?
이미 손실을 수치화하는 몇 가지 방법을 살펴봤습니다. 복잡성을 어떻게 수치화할 수 있나요? 다음 연습을 통해 탐색을 시작하세요.
연습문제: 직관력 테스트
지금까지 복잡도가 실제로 무엇인지에 관해 매우 모호하게 설명했습니다. 다음 아이디어 중 합리적인 복잡도 측정항목은 무엇이라고 생각하시나요?
복잡도는 모델의 가중치에 대한 함수입니다.
예, 이는 일부 모델의 복잡도를 측정하는 한 가지 방법입니다. 이 측정항목을 L1 정규화라고 합니다.
복잡도는 모델 가중치의 제곱에 대한 함수입니다.
예, 이 방법으로 일부 모델의 복잡성을 측정할 수 있습니다. 이 측정항목을 L2 정규화라고 합니다.
[[["이해하기 쉬움","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-14(UTC)"],[[["\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,["The 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\nExercises: Check your understanding \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\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\nLoss 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\nYou've already seen a few different ways of quantifying loss. How would\nyou quantify complexity? Start your exploration through the following exercise:\n\nExercise: Check your intuition \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)"]]