임곗값 및 혼동 행렬
컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
특정 이메일이 스팸일 확률을 나타내는 0과 1 사이의 값을 예측하는 스팸 이메일 감지를 위한 로지스틱 회귀 모델이 있다고 가정해 보겠습니다. 예를 들어 예측값이 0.50이면 이메일이 스팸일 확률이 50% 이고, 예측값이 0.75이면 이메일이 스팸일 확률이 75% 임을 나타냅니다.
이메일 애플리케이션에 이 모델을 배포하여 스팸을 별도의 메일 폴더로 필터링하려고 합니다. 하지만 이렇게 하려면 모델의 원시 숫자 출력 (예: 0.75
)를 '스팸' 또는 '스팸 아님'이라는 두 카테고리 중 하나로 분류합니다.
이 변환을 수행하려면 분류 임곗값이라고 하는 임곗값 확률을 선택합니다. 임곗값을 초과하는 확률이 있는 예시는 테스트 중인 클래스인 양성 클래스 (여기서는 spam
)에 할당됩니다. 확률이 더 낮은 예시는 대체 클래스인 음성 클래스 (여기서는 not spam
)에 할당됩니다.
분류 기준에 대한 자세한 내용을 보려면 여기를 클릭하세요
예측 점수가 분류 임곗값과 같으면 어떻게 될까요 (예: 분류 임곗값이 0.5인 경우 점수가 0.5)? 이 사례의 처리는 분류 모델에 선택된 구현에 따라 다릅니다. Keras 라이브러리는 점수와 임곗값이 같은 경우 음성 클래스를 예측하지만 다른 도구/프레임워크는 이 사례를 다르게 처리할 수 있습니다.
모델이 한 이메일의 점수를 0.99로 매겨 이메일이 스팸일 확률이 99% 라고 예측하고 다른 이메일의 점수를 0.51로 매겨 스팸일 확률이 51% 라고 예측한다고 가정해 보겠습니다. 분류 임곗값을 0.5로 설정하면 모델은 두 이메일을 모두 스팸으로 분류합니다. 임곗값을 0.95로 설정하면 점수가 0.99인 이메일만 스팸으로 분류됩니다.
0.5는 직관적인 기준점처럼 보이지만, 한 유형의 잘못된 분류의 비용이 다른 유형보다 크거나 클래스가 불균형한 경우에는 적절하지 않습니다. 이메일의 0.01% 만 스팸이거나 스팸을 받은편지함에 허용하는 것보다 정상적인 이메일을 잘못 분류하는 것이 더 나쁜 경우, 모델에서 스팸일 가능성이 50% 이상이라고 간주하는 모든 항목을 스팸으로 라벨링하면 바람직하지 않은 결과가 발생합니다.
혼동 행렬
확률 점수는 현실 또는 정답이 아닙니다. 이진 분류자의 각 출력에는 4가지 결과가 있을 수 있습니다. 스팸 분류기 예시에서 정답을 열로, 모델의 예측을 행으로 배치하면 혼동 행렬이라고 하는 다음 표가 표시됩니다.
| 실제 양성 | 실제 음성 |
긍정적인 예측 | 참양성 (TP): 스팸 이메일이 스팸 이메일로 올바르게 분류된 경우입니다. 스팸 폴더로 자동 전송되는 스팸 메일입니다. | 거짓양성 (FP): 스팸이 아닌 이메일이 스팸으로 잘못 분류된 경우입니다. 이러한 이메일은 스팸 폴더로 이동하는 적법한 이메일입니다. |
예측된 부정적 | 거짓음성 (FN): 스팸 이메일이 스팸이 아닌 것으로 잘못 분류된 경우입니다. 스팸 필터에 걸리지 않고 받은편지함으로 전송되는 스팸 이메일입니다. | 참음성 (TN): 스팸이 아닌 이메일이 스팸이 아닌 것으로 올바르게 분류된 경우입니다. 받은편지함으로 직접 전송되는 적법한 이메일입니다. |
각 행의 합계는 유효성에 관계없이 모든 예측 양성 (TP + FP) 및 모든 예측 음성 (FN + TN)을 제공합니다. 각 열의 합계는 모델 분류와 관계없이 모든 실제 양성 (TP + FN)과 모든 실제 음성(FP + TN)을 제공합니다.
실제 양성의 총계가 실제 음성의 총계에 근접하지 않으면 데이터 세트가 불균형합니다. 불균형 데이터 세트의 예로는 구름 사진 수천 개의 세트가 있을 수 있습니다. 이 세트에서 관심 있는 희귀한 구름 유형(예: 울투스 구름)이 몇 번만 표시됩니다.
임곗값이 참양성, 거짓양성, 거짓음성에 미치는 영향
기준점이 다르면 일반적으로 참양성, 거짓양성, 참음성, 거짓음성의 수가 달라집니다. 다음 동영상에서 그 이유를 설명합니다.
임곗값을 직접 변경해 보세요.
이 위젯에는 다음과 같은 세 가지 장난감 데이터 세트가 포함되어 있습니다.
- 분리됨: 양성 예시와 음성 예시가 일반적으로 잘 구분되며 대부분의 양성 예시가 음성 예시보다 점수가 높습니다.
- 분리되지 않음: 양성 예시가 음성 예시보다 점수가 낮은 예시가 많고 음성 예시가 양성 예시보다 점수가 높은 예시가 많습니다.
- 불균형: 양성 클래스의 예가 몇 개만 포함되어 있습니다.
이해도 확인
1. 피싱 및 멀웨어 웹사이트가 1 (참) 라벨이 지정된 클래스에 있고 무해한 웹사이트가 0 (거짓) 라벨이 지정된 클래스에 있는 피싱 또는 멀웨어 분류 모델을 생각해 보세요. 이 모델은 합법적인 웹사이트를 멀웨어로 잘못 분류합니다. 이를 뭐라고 부르나요?
거짓양성
음성 예시 (합법적인 사이트)가 양성 예시 (멀웨어 사이트)로 잘못 분류되었습니다.
참양성
참양성은 멀웨어로 올바르게 분류된 멀웨어 사이트입니다.
거짓음성
거짓음성은 멀웨어 사이트가 합법적인 사이트로 잘못 분류된 경우입니다.
참음성
참음성은 정상 사이트로 올바르게 분류된 정상 사이트입니다.
2. 일반적으로 분류 기준점이 증가하면 거짓양성 수는 어떻게 되나요? 참양성은 어떻게 되나요? 위의 슬라이더를 사용해 보세요.
참양성과 거짓양성 모두 감소합니다.
임곗값이 증가하면 모델은 참양성과 거짓양성 모두 전반적으로 더 적게 예측할 가능성이 높습니다. 임계값이 .9999인 스팸 분류기는 분류 확률이 99.99% 이상이라고 판단되는 경우에만 이메일을 스팸으로 라벨합니다. 즉, 정상 이메일에 잘못된 라벨을 지정할 가능성은 매우 낮지만 실제 스팸 이메일을 놓칠 가능성이 높습니다.
참양성과 거짓양성이 모두 증가합니다.
위의 슬라이더를 사용하여 임곗값을 0.1로 설정한 다음 0.9로 드래그해 보세요. 거짓양성 수와 참양성 수는 어떻게 되나요?
참양성이 증가합니다. 거짓양성이 감소합니다.
위의 슬라이더를 사용하여 임곗값을 0.1로 설정한 다음 0.9로 드래그해 보세요. 거짓양성 수와 참양성 수는 어떻게 되나요?
3. 일반적으로 분류 기준점이 증가하면 거짓 음성의 수는 어떻게 되나요? 참음성은 어떨까요? 위의 슬라이더를 사용해 보세요.
참음성과 거짓음성 모두 증가합니다.
임곗값이 증가하면 모델은 참음성과 거짓음성 모두 더 많이 예측할 가능성이 높습니다. 임곗값이 매우 높으면 스팸과 스팸이 아닌 메일 모두 거의 대부분 스팸이 아닌 것으로 분류됩니다.
참음성과 거짓음성 모두 감소합니다.
위의 슬라이더를 사용하여 임곗값을 0.1로 설정한 다음 0.9로 드래그해 보세요. 거짓음성 수와 참음성 수는 어떻게 되나요?
참음성이 증가합니다. 거짓음성이 감소합니다.
위의 슬라이더를 사용하여 임곗값을 0.1로 설정한 다음 0.9로 드래그해 보세요. 거짓음성 수와 참음성 수는 어떻게 되나요?
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-05-22(UTC)
[null,null,["최종 업데이트: 2025-05-22(UTC)"],[],[],null,["Let's say you have a logistic regression model for spam-email detection that\npredicts a value between 0 and 1, representing the probability that a given\nemail is spam. A prediction of 0.50 signifies a 50% likelihood that the email is\nspam, a prediction of 0.75 signifies a 75% likelihood that the email is spam,\nand so on.\n\nYou'd like to deploy this model in an email application to filter spam into\na separate mail folder. But to do so, you need to convert the model's raw\nnumerical output (e.g., `0.75`) into one of two categories: \"spam\" or \"not\nspam.\"\n\nTo make this conversion, you choose a threshold probability, called a\n[**classification threshold**](/machine-learning/glossary#classification-threshold).\nExamples with a probability above the threshold value are then assigned\nto the [**positive class**](/machine-learning/glossary#positive_class),\nthe class you are testing for (here, `spam`). Examples with a lower\nprobability are assigned to the [**negative class**](/machine-learning/glossary#negative_class),\nthe alternative class (here, `not spam`). \n\n**Click here for more details on the classification threshold**\n\nYou may be wondering: what happens if the predicted score is equal to\nthe classification threshold (for instance, a score of 0.5 where\nthe classification threshold is also 0.5)? Handling for this case\ndepends on the particular implementation chosen for the classification\nmodel. The [Keras](https://keras.io/)\nlibrary predicts the negative class if the score and threshold\nare equal, but other tools/frameworks may handle this case\ndifferently.\n\nSuppose the model scores one email as 0.99, predicting\nthat email has a 99% chance of being spam, and another email as\n0.51, predicting it has a 51% chance of being spam. If you set the\nclassification threshold to 0.5, the model will classify both emails as\nspam. If you set the threshold to 0.95, only the email scoring 0.99 will\nbe classified as spam.\n\nWhile 0.5 might seem like an intuitive threshold, it's not a good idea if the\ncost of one type of wrong classification is greater than the other, or if the\nclasses are imbalanced. If only 0.01% of emails are spam, or if misfiling\nlegitimate emails is worse than letting spam into the inbox,\nlabeling anything the model considers at least 50% likely to be spam\nas spam produces undesirable results.\n\nConfusion matrix\n\nThe probability score is not reality, or\n[**ground truth**](/machine-learning/glossary#ground_truth).\nThere are four possible outcomes for each output from a binary classifier.\nFor the spam classifier example, if you lay out the ground truth as columns\nand the model's prediction as rows, the following table, called a\n[**confusion matrix**](/machine-learning/glossary#confusion_matrix), is the\nresult:\n\n| | Actual positive | Actual negative |\n| Predicted positive | **True positive (TP)**: A spam email correctly classified as a spam email. These are the spam messages automatically sent to the spam folder. | **False positive (FP)**: A not-spam email misclassified as spam. These are the legitimate emails that wind up in the spam folder. |\n| Predicted negative | **False negative (FN)**: A spam email misclassified as not-spam. These are spam emails that aren't caught by the spam filter and make their way into the inbox. | **True negative (TN)**: A not-spam email correctly classified as not-spam. These are the legitimate emails that are sent directly to the inbox. |\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|\n\nNotice that the total in each row gives all predicted positives (TP + FP) and\nall predicted negatives (FN + TN), regardless of validity. The total in each\ncolumn, meanwhile, gives all real positives (TP + FN) and all real negatives\n(FP + TN) regardless of model classification.\n\nWhen the total of actual positives is not close to the total of actual\nnegatives, the dataset is\n[**imbalanced**](/machine-learning/glossary#class_imbalanced_data_set). An instance\nof an imbalanced dataset might be a set of thousands of photos of clouds, where\nthe rare cloud type you are interested in, say, volutus clouds, only appears\na few times.\n\nEffect of threshold on true and false positives and negatives\n\nDifferent thresholds usually result in different numbers of true and false\npositives and true and false negatives. The following video explains why this is\nthe case. \n\nTry changing the threshold yourself.\n\nThis widget includes three toy datasets:\n\n- **Separated**, where positive examples and negative examples are generally well differentiated, with most positive examples having higher scores than negative examples.\n- **Unseparated**, where many positive examples have lower scores than negative examples, and many negative examples have higher scores than positive examples.\n- **Imbalanced**, containing only a few examples of the positive class.\n\nCheck your understanding \n1. Imagine a phishing or malware classification model where phishing and malware websites are in the class labeled **1** (true) and harmless websites are in the class labeled **0** (false). This model mistakenly classifies a legitimate website as malware. What is this called? \nA false positive \nA negative example (legitimate site) has been wrongly classified as a positive example (malware site). \nA true positive \nA true positive would be a malware site correctly classified as malware. \nA false negative \nA false negative would be a malware site incorrectly classified as a legitimate site. \nA true negative \nA true negative would be a legitimate site correctly classified as a legitimate site. \n2. In general, what happens to the number of false positives when the classification threshold increases? What about true positives? Experiment with the slider above. \nBoth true and false positives decrease. \nAs the threshold increases, the model will likely predict fewer positives overall, both true and false. A spam classifier with a threshold of .9999 will only label an email as spam if it considers the classification to be at least 99.99% likely, which means it is highly unlikely to mislabel a legitimate email, but also likely to miss actual spam email. \nBoth true and false positives increase. \nUsing the slider above, try setting the threshold to 0.1, then dragging it to 0.9. What happens to the number of false positives and true positives? \nTrue positives increase. False positives decrease. \nUsing the slider above, try setting the threshold to 0.1, then dragging it to 0.9. What happens to the number of false positives and true positives? \n3. In general, what happens to the number of false negatives when the classification threshold increases? What about true negatives? Experiment with the slider above. \nBoth true and false negatives increase. \nAs the threshold increases, the model will likely predict more negatives overall, both true and false. At a very high threshold, almost all emails, both spam and not-spam, will be classified as not-spam. \nBoth true and false negatives decrease. \nUsing the slider above, try setting the threshold to 0.1, then dragging it to 0.9. What happens to the number of false negatives and true negatives? \nTrue negatives increase. False negatives decrease. \nUsing the slider above, try setting the threshold to 0.1, then dragging it to 0.9. What happens to the number of false negatives and true negatives?\n| **Key terms:**\n|\n| - [Binary classification](/machine-learning/glossary#binary-classification)\n| - [Class-imbalanced dataset](/machine-learning/glossary#class_imbalanced_data_set)\n| - [Classification threshold](/machine-learning/glossary#classification-threshold)\n| - [Confusion matrix](/machine-learning/glossary#confusion_matrix)\n| - [Ground truth](/machine-learning/glossary#ground_truth)\n| - [Negative class](/machine-learning/glossary#negative_class)\n- [Positive class](/machine-learning/glossary#positive_class) \n[Help Center](https://support.google.com/machinelearningeducation)"]]