로지스틱 회귀: 손실 및 정규화
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
로지스틱 회귀 모델은 선형 회귀 모델과 동일한 프로세스를 사용하여 학습되지만, 두 가지 주요 차이점이 있습니다.
다음 섹션에서는 이러한 두 가지 고려사항을 자세히 설명합니다.
로그 손실
선형 회귀 모듈에서는 제곱 손실(L2 손실이라고도 함)을 손실 함수로 사용했습니다.
제곱 손실은 출력값의 변화율이 일정한 선형 모델에 효과적입니다. 예를 들어 선형 모델 $y' = b + 3x_1$의 경우 $x_1$ 입력값이 1씩 증가할 때마다 $y'$ 출력값이 3씩 증가합니다.
하지만 로지스틱 회귀 모델의 변화율은 일정하지 않습니다.
확률 계산에서 확인했듯이 시그모이드 곡선은 선형이 아닌 s자 모양입니다. 로그 오즈($z$) 값이 0에 가까워질 때 $z$가 약간 증가하면 $y$가 큰 양수 또는 음수일 때보다 $y$ 변화가 훨씬 커집니다. 다음 표는 5~10 입력값에 대한 시그모이드 함수의 출력과 더불어 결과의 차이를 포착하는 데 필요한 해당 정밀도를 보여줍니다.
입력 |
로지스틱 출력 |
필요한 정밀도 자릿수 |
5 |
0.993 |
3 |
6 |
0.997 |
3 |
7 |
0.999 |
3 |
8 |
0.9997 |
4 |
9 |
0.9999 |
4 |
10 |
0.99998 |
5 |
제곱 손실을 사용하여 시그모이드 함수의 오차를 계산했다면, 출력이 0
과 1
에 가까워질수록 이러한 값을 추적하는 데 필요한 정밀도를 유지하기 위해 더 많은 메모리가 필요합니다.
대신 로지스틱 회귀의 손실 함수는 로그 손실입니다. 로그 손실 방정식은 데이터와 예측치의 차이만이 아닌 변화 규모의 대수를 반환합니다. 로그 손실은 다음과 같이 계산됩니다.
\(\text{Log Loss} = \sum_{(x,y)\in D} -y\log(y') - (1 - y)\log(1 - y')\)
각 항목의 의미는 다음과 같습니다.
-
\((x,y)\in D\) : \((x,y)\) 쌍인 라벨이 있는 예가 많이 포함된 데이터 세트입니다.
-
\(y\) : 라벨이 있는 예의 라벨입니다. 이는 로지스틱 회귀이므로 \(y\) 의 모든 값은 0이나 1이어야 합니다.
-
\(y'\) : \(x\)의 특성 집합을 고려할 때 모델의 예측(0과 1 사이)입니다.
로지스틱 회귀의 정규화
정규화는 학습 중에 모델 복잡성에 페널티를 적용하는 메커니즘으로, 로지스틱 회귀 모델링에 매우 중요합니다. 정규화가 없으면 로지스틱 회귀의 점근적 특성으로 인해 모델에 많은 수의 특성이 있는 경우 손실이 0으로 계속 이동하게 됩니다. 따라서 대부분의 로지스틱 회귀 모델은 다음 두 가지 전략 중 하나를 사용하여 모델 복잡성을 줄입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-01-09(UTC)
[null,null,["최종 업데이트: 2025-01-09(UTC)"],[[["\u003cp\u003eLogistic regression models are trained similarly to linear regression models but use Log Loss instead of squared loss and require regularization.\u003c/p\u003e\n"],["\u003cp\u003eLog Loss is used in logistic regression because the rate of change isn't constant, requiring varying precision levels unlike squared loss used in linear regression.\u003c/p\u003e\n"],["\u003cp\u003eRegularization, such as L2 regularization or early stopping, is crucial in logistic regression to prevent overfitting due to the model's asymptotic nature.\u003c/p\u003e\n"]]],[],null,["# Logistic regression: Loss and regularization\n\n[**Logistic regression**](/machine-learning/glossary#logistic_regression)\nmodels are trained using the same process as\n[**linear regression**](/machine-learning/crash-course/linear-regression)\nmodels, with two key distinctions:\n\n- Logistic regression models use [**Log Loss**](/machine-learning/glossary#Log_Loss) as the loss function instead of [**squared loss**](/machine-learning/glossary#l2-loss).\n- Applying [regularization](/machine-learning/crash-course/overfitting/regularization) is critical to prevent [**overfitting**](/machine-learning/glossary#overfitting).\n\nThe following sections discuss these two considerations in more depth.\n\nLog Loss\n--------\n\nIn the [Linear regression module](/machine-learning/crash-course/linear-regression),\nyou used [**squared loss**](/machine-learning/glossary#l2-loss) (also called\nL~2~ loss) as the\n[**loss function**](/machine-learning/glossary#loss-function).\nSquared loss works well for a linear\nmodel where the rate of change of the output values is constant. For example,\ngiven the linear model $y' = b + 3x_1$, each time you increment the input\nvalue $x_1$ by 1, the output value $y'$ increases by 3.\n\nHowever, the rate of change of a logistic regression model is *not* constant.\nAs you saw in [Calculating a probability](/machine-learning/crash-course/logistic-regression/sigmoid-function), the\n[**sigmoid**](/machine-learning/glossary#sigmoid-function) curve is s-shaped\nrather than linear. When the log-odds ($z$) value is closer to 0, small\nincreases in $z$ result in much larger changes to $y$ than when $z$ is a large\npositive or negative number. The following table shows the sigmoid function's\noutput for input values from 5 to 10, as well as the corresponding precision\nrequired to capture the differences in the results.\n\n| input | logistic output | required digits of precision |\n|-------|-----------------|------------------------------|\n| 5 | 0.993 | 3 |\n| 6 | 0.997 | 3 |\n| 7 | 0.999 | 3 |\n| 8 | 0.9997 | 4 |\n| 9 | 0.9999 | 4 |\n| 10 | 0.99998 | 5 |\n\nIf you used squared loss to calculate errors for the sigmoid function, as the\noutput got closer and closer to `0` and `1`, you would need more memory to\npreserve the precision needed to track these values.\n\nInstead, the loss function for logistic regression is\n[**Log Loss**](/machine-learning/glossary#Log_Loss). The\nLog Loss equation returns the logarithm of the magnitude of the change, rather\nthan just the distance from data to prediction. Log Loss is calculated as\nfollows:\n\n\\\\(\\\\text{Log Loss} = \\\\sum_{(x,y)\\\\in D} -y\\\\log(y') - (1 - y)\\\\log(1 - y')\\\\)\n\n\u003cbr /\u003e\n\nwhere:\n\n- \\\\((x,y)\\\\in D\\\\) is the dataset containing many labeled examples, which are \\\\((x,y)\\\\) pairs.\n- \\\\(y\\\\) is the label in a labeled example. Since this is logistic regression, every value of \\\\(y\\\\) must either be 0 or 1.\n- \\\\(y'\\\\) is your model's prediction (somewhere between 0 and 1), given the set of features in \\\\(x\\\\).\n\nRegularization in logistic regression\n-------------------------------------\n\n[**Regularization**](/machine-learning/glossary#regularization), a mechanism for\npenalizing model complexity during training, is extremely important in logistic\nregression modeling. Without regularization, the asymptotic nature of logistic\nregression would keep driving loss towards 0 in cases where the model has a\nlarge number of features. Consequently, most logistic regression models use one\nof the following two strategies to decrease model complexity:\n\n- [L~2~ regularization](/machine-learning/crash-course/overfitting/regularization)\n- [Early stopping](/machine-learning/crash-course/overfitting/regularization#early_stopping_an_alternative_to_complexity-based_regularization): Limiting the number of training steps to halt training while loss is still decreasing.\n\n| **Note:** You'll learn more about regularization in the [Datasets, Generalization, and Overfitting](/machine-learning/crash-course/overfitting) module of the course.\n| **Key terms:**\n|\n| - [Gradient descent](/machine-learning/glossary#gradient-descent)\n| - [Linear regression](/machine-learning/glossary#linear_regression)\n| - [Log Loss](/machine-learning/glossary#Log_Loss)\n| - [Logistic regression](/machine-learning/glossary#logistic_regression)\n| - [Loss function](/machine-learning/glossary#loss-function)\n| - [Overfitting](/machine-learning/glossary#overfitting)\n| - [Regularization](/machine-learning/glossary#regularization)\n- [Squared loss](/machine-learning/glossary#l2-loss) \n[Help Center](https://support.google.com/machinelearningeducation)"]]