손실은 모델의 예측이 얼마나 잘못되었는지를 설명하는 수치 측정항목입니다. 손실은 모델의 예측과 실제 라벨 간의 거리를 측정합니다. 모델 학습의 목표는 손실을 최소화하여 가능한 가장 낮은 값으로 줄이는 것입니다.
다음 이미지에서 데이터 포인트에서 모델로 그려진 화살표로 손실을 시각화할 수 있습니다. 화살표는 모델의 예측이 실제 값과 얼마나 차이가 나는지 보여줍니다.
그림 8. 손실은 실제 값에서 예측 값으로 측정됩니다.
손실 거리
통계 및 머신러닝에서 손실은 예측값과 실제 값 간의 차이를 측정합니다. 손실은 방향이 아닌 값 간의 거리에 중점을 둡니다. 예를 들어 모델이 2를 예측했지만 실제 값이 5인 경우 손실이 음수 ($ 2-5=-3 $)인 것은 중요하지 않습니다. 대신 값 사이의 거리가 $ 3$인 것이 중요합니다. 따라서 손실을 계산하는 모든 방법은 부호를 삭제합니다.
L1 손실과 L2 손실(또는 MAE와 MSE)의 기능적 차이는 제곱입니다. 예측과 라벨 간의 차이가 클 때 제곱하면 손실이 훨씬 커집니다. 차이가 작으면 (1 미만) 제곱하면 손실이 더 작아집니다.
한 번에 여러 예시를 처리할 때는 MAE를 사용하든 MSE를 사용하든 모든 예시에서 손실을 평균하는 것이 좋습니다.
손실 계산 예
이전 최적선을 사용하여 단일 예의 L2 손실을 계산합니다. 최적합 선에서 가중치와 편향에 대한 값은 다음과 같습니다.
$ \small{Weight: -4.6} $
$ \small{Bias: 34} $
모델에서 2,370파운드 자동차의 연비를 갤런당 23.1마일로 예측했지만 실제 연비는 갤런당 26마일인 경우 L2 손실은 다음과 같이 계산됩니다.
값
등식
결과
예측
$\small{bias + (weight * feature\ value)}$
$\small{34 + (-4.6*2.37)}$
$\small{23.1}$
실제 금액
$ \small{ label } $
$ \small{ 26 } $
L2 손실
$ \small{ (실제\ 값 - 예측\ 값)^2 } $
$\small{ (26 - 23.1)^2 }$
$\small{8.41}$
이 예에서 해당 단일 데이터 포인트의 L2 손실은 8.41입니다.
손실 선택
MAE 또는 MSE 사용 여부는 데이터 세트와 특정 예측을 처리하는 방식에 따라 달라질 수 있습니다. 데이터 세트의 대부분의 특성 값은 일반적으로 고유한 범위에 속합니다. 예를 들어 자동차는 일반적으로 2,000~5,000파운드이며 갤런당 8~50마일을 주행합니다. 8,000파운드 자동차나 갤런당 100마일을 주행하는 자동차는 일반적인 범위를 벗어나므로 이상치로 간주됩니다.
이상치는 모델의 예측이 실제 값에서 얼마나 벗어났는지를 나타낼 수도 있습니다. 예를 들어 3,000파운드는 일반적인 자동차 무게 범위에 속하고 갤런당 40마일은 일반적인 연비 범위에 속합니다. 하지만 갤런당 40마일을 주행하는 3,000파운드 자동차는 모델의 예측 측면에서 이상치입니다. 모델은 3,000파운드 자동차가 갤런당 약 20마일을 주행할 것으로 예측하기 때문입니다.
최적의 손실 함수를 선택할 때는 모델이 이상치를 어떻게 처리해야 하는지 고려하세요. 예를 들어 MSE는 모델을 이상치에 더 가깝게 이동하는 반면 MAE는 그렇지 않습니다. L2 손실은 L1 손실보다 이상치에 훨씬 높은 페널티를 적용합니다. 예를 들어 다음 이미지는 MAE를 사용하여 학습된 모델과 MSE를 사용하여 학습된 모델을 보여줍니다. 빨간색 선은 예측을 수행하는 데 사용되는 완전히 학습된 모델을 나타냅니다. 이상치는 MAE로 학습된 모델보다 MSE로 학습된 모델에 더 가깝습니다.
그림 9. MSE로 학습된 모델은 모델을 이상치에 더 가깝게 이동시킵니다.
그림 10. MAE로 학습된 모델은 이상치에서 더 멀리 떨어져 있습니다.
모델과 데이터 간의 관계를 참고하세요.
MSE 모델이 이상치에 더 가깝지만 다른 대부분의 데이터 포인트와는 더 멀리 떨어져 있습니다.
MAE 모델이 이상치에서 더 멀리 떨어져 있지만 대부분의 다른 데이터 포인트에 더 가깝습니다.
손실 측정항목 선택에 관한 가이드라인을 자세히 보려면 아이콘을 클릭하세요.
MSE 선택:
큰 오류에 큰 페널티를 적용하려는 경우
이상치가 중요하며 모델이 고려해야 하는 실제 데이터 분산을 나타낸다고 생각하는 경우
MAE 선택:
데이터 세트에 모델에 지나치게 영향을 미치지 않도록 하려는 이상치가 있는 경우 MAE가 더 강력합니다.
평균 오류 크기로 더 직접 해석할 수 있는 손실 함수를 선호하는 경우
실제로 측정항목 선택은 특정 비즈니스 문제와 비용이 더 많이 드는 오류 유형에 따라 달라질 수도 있습니다.
이해도 확인
데이터 세트에 적합한 선형 모델의 다음 두 가지 플롯을 살펴보세요.
위 도표에 표시된 두 개의 선형 모델 중 도표에 표시된 데이터 포인트에 대해 평가했을 때 평균 제곱 오차 (MSE)가 더 높은 것은 무엇인가요?
왼쪽의 모델
이 줄의 6개 예시에서는 총 손실이 0입니다. 선에 있지 않은 네 가지 예는 선에서 크게 벗어나지 않으므로 오프셋을 제곱해도 값이 낮습니다. $MSE = \frac{0^2 + 1^2 + 0^2 + 1^2 + 0^2 + 1^2 + 0^2 + 1^2 + 0^2 + 0^2} {10} = 0.4$
오른쪽 모델
이 줄의 8개 예시에는 총 손실 0이 발생합니다. 그러나, 선에서 벗어난 점은 2개밖에 안 되지만, 2개의 점 모두 선에서 벗어난 정도가 왼쪽 그림의 이상점에 비해 2배 더 큽니다. 제곱 손실값의 경우 이러한 차이가 증폭되므로 오프셋 2의 경우 오프셋 1보다 4배 더 큰 손실이 발생합니다. $MSE = \frac{0^2 + 0^2 + 0^2 + 2^2 + 0^2 + 0^2 + 0^2 + 2^2 + 0^2 + 0^2} {10} = 0.8$
[[["이해하기 쉬움","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"]],["최종 업데이트: 2025-08-21(UTC)"],[[["\u003cp\u003eLoss is a numerical value indicating the difference between a model's predictions and the actual values.\u003c/p\u003e\n"],["\u003cp\u003eThe goal of model training is to minimize loss, bringing it as close to zero as possible.\u003c/p\u003e\n"],["\u003cp\u003eTwo common methods for calculating loss are Mean Absolute Error (MAE) and Mean Squared Error (MSE), which differ in their sensitivity to outliers.\u003c/p\u003e\n"],["\u003cp\u003eChoosing between MAE and MSE depends on the dataset and how you want the model to handle outliers, with MSE penalizing them more heavily.\u003c/p\u003e\n"]]],[],null,["[**Loss**](/machine-learning/glossary#loss) is a numerical metric that describes\nhow wrong a model's [**predictions**](/machine-learning/glossary#prediction)\nare. Loss measures the distance between the model's predictions and the actual\nlabels. The goal of training a model is to minimize the loss, reducing it to its\nlowest possible value.\n\nIn the following image, you can visualize loss as arrows drawn from the data\npoints to the model. The arrows show how far the model's predictions are from\nthe actual values.\n\n**Figure 9**. Loss is measured from the actual value to the predicted value.\n\nDistance of loss\n\nIn statistics and machine learning, loss measures the difference between the\npredicted and actual values. Loss focuses on the *distance* between the values,\nnot the direction. For example, if a model predicts 2, but the actual value is\n5, we don't care that the loss is negative ($ 2-5=-3 $).\nInstead, we care that the *distance* between the values is $ 3 $. Thus, all\nmethods for calculating loss remove the sign.\n\nThe two most common methods to remove the sign are the following:\n\n- Take the absolute value of the difference between the actual value and the prediction.\n- Square the difference between the actual value and the prediction.\n\nTypes of loss\n\nIn linear regression, there are four main types of loss, which are outlined in\nthe following table.\n\n| Loss type | Definition | Equation |\n|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|\n| **[L~1~ loss](/machine-learning/glossary#l1-loss)** | The sum of the absolute values of the difference between the predicted values and the actual values. | $ ∑ \\| actual\\\\ value - predicted\\\\ value \\| $ |\n| **[Mean absolute error (MAE)](/machine-learning/glossary#mean-absolute-error-mae)** | The average of L~1~ losses across a set of \\*N\\* examples. | $ \\\\frac{1}{N} ∑ \\| actual\\\\ value - predicted\\\\ value \\| $ |\n| **[L~2~ loss](/machine-learning/glossary#l2-loss)** | The sum of the squared difference between the predicted values and the actual values. | $ ∑(actual\\\\ value - predicted\\\\ value)\\^2 $ |\n| **[Mean squared error (MSE)](/machine-learning/glossary#mean-squared-error-mse)** | The average of L~2~ losses across a set of \\*N\\* examples. | $ \\\\frac{1}{N} ∑ (actual\\\\ value - predicted\\\\ value)\\^2 $ |\n\nThe functional difference between L~1~ loss and L~2~ loss\n(or between MAE and MSE) is squaring. When the difference between the\nprediction and label is large, squaring makes the loss even larger. When the\ndifference is small (less than 1), squaring makes the loss even smaller.\n\nWhen processing multiple examples at once, we recommend averaging the losses\nacross all the examples, whether using MAE or MSE.\n\nCalculating loss example\n\nUsing the previous [best fit line](/machine-learning/crash-course/linear-regression#linear_regression_equation),\nwe'll calculate L~2~ loss for a single example. From the\nbest fit line, we had the following values for weight and bias:\n\n- $ \\\\small{Weight: -4.6} $\n- $ \\\\small{Bias: 34} $\n\nIf the model predicts that a 2,370-pound car gets 23.1 miles per gallon, but it\nactually gets 26 miles per gallon, we would calculate the L~2~ loss as\nfollows:\n| **Note:** The formula uses 2.37 because the graphs are scaled to 1000s of pounds\n\n| Value | Equation | Result |\n|--------------|------------------------------------------------------------------------------------|-------------------|\n| Prediction | $\\\\small{bias + (weight \\* feature\\\\ value)}$ $\\\\small{34 + (-4.6\\*2.37)}$ | $\\\\small{23.1}$ |\n| Actual value | $ \\\\small{ label } $ | $ \\\\small{ 26 } $ |\n| L~2~ loss | $ \\\\small{ (actual\\\\ value - predicted\\\\ value)\\^2 } $ $\\\\small{ (26 - 23.1)\\^2 }$ | $\\\\small{8.41}$ |\n\nIn this example, the L~2~ loss for that single data point is 8.41.\n\nChoosing a loss\n\nDeciding whether to use MAE or MSE can depend on the dataset and the way you\nwant to handle certain predictions. Most feature values in a dataset typically\nfall within a distinct range. For example, cars are normally between 2000 and\n5000 pounds and get between 8 to 50 miles per gallon. An 8,000-pound car,\nor a car that gets 100 miles per gallon, is outside the typical range and would\nbe considered an [**outlier**](/machine-learning/glossary#outliers).\n\nAn outlier can also refer to how far off a model's predictions are from the real\nvalues. For instance, 3,000 pounds is within the typical car-weight range, and\n40 miles per gallon is within the typical fuel-efficiency range. However, a\n3,000-pound car that gets 40 miles per gallon would be an outlier in terms of\nthe model's prediction because the model would predict that a 3,000-pound car\nwould get around 20 miles per gallon.\n\nWhen choosing the best loss function, consider how you want the model to treat\noutliers. For instance, MSE moves the model more toward the outliers, while MAE\ndoesn't. L~2~ loss incurs a much higher penalty for an outlier than\nL~1~ loss. For example, the following images show a model trained\nusing MAE and a model trained using MSE. The red line represents a fully\ntrained model that will be used to make predictions. The outliers are closer to\nthe model trained with MSE than to the model trained with MAE.\n\n**Figure 10**. A model trained with MSE moves the model closer to the outliers.\n\n**Figure 11**. A model trained with MAE is farther from the outliers.\n\nNote the relationship between the model and the data:\n\n- **MSE**. The model is closer to the outliers but further away from most of\n the other data points.\n\n- **MAE**. The model is further away from the outliers but closer to most of\n the other data points.\n\n\u003cbr /\u003e\n\nCheck Your Understanding\n\n\u003cbr /\u003e\n\nConsider the following two plots:\n\n|---|---|\n| | |\n\nWhich of the two data sets shown in the preceding plots has the **higher** Mean Squared Error (MSE)? \nThe dataset on the left. \nThe six examples on the line incur a total loss of 0.4. The four examples not on the line are not very far off the line, so even squaring their offset still yields a low value: $MSE = \\\\frac{0\\^2 + 1\\^2 + 0\\^2 + 1\\^2 + 0\\^2 + 1\\^2 + 0\\^2 + 1\\^2 + 0\\^2 + 0\\^2} {10} = 0.4$ \nThe dataset on the right. \nThe eight examples on the line incur a total loss of 0.8. However, although only two points lay off the line, both of those points are *twice* as far off the line as the outlier points in the left figure. Squared loss amplifies those differences, so an offset of two incurs a loss four times as great as an offset of one: $MSE = \\\\frac{0\\^2 + 0\\^2 + 0\\^2 + 2\\^2 + 0\\^2 + 0\\^2 + 0\\^2 + 2\\^2 + 0\\^2 + 0\\^2} {10} = 0.8$\n| **Key terms:**\n|\n| - [Mean absolute error (MAE)](/machine-learning/glossary#mean-absolute-error-mae)\n| - [Mean squared error (MSE)](/machine-learning/glossary#mean-squared-error-mse)\n| - [L~1~](/machine-learning/glossary#l1-loss)\n| - [L~2~](/machine-learning/glossary#l2-loss)\n| - [Loss](/machine-learning/glossary#loss)\n| - [Outlier](/machine-learning/glossary#outliers)\n- [Prediction](/machine-learning/glossary#prediction) \n[Help Center](https://support.google.com/machinelearningeducation)"]]