آستانه ها و ماتریس سردرگمی
با مجموعهها، منظم بمانید ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
فرض کنید شما یک مدل رگرسیون لجستیک برای شناسایی ایمیلهای هرزنامه دارید که مقداری بین 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 درصد آن را بهعنوان هرزنامه میداند، نتایج نامطلوبی ایجاد میکند.
ماتریس سردرگمی
امتیاز احتمال واقعیت یا حقیقت پایه نیست. چهار نتیجه ممکن برای هر خروجی از یک طبقه بندی کننده باینری وجود دارد. برای مثال طبقهبندی کننده هرزنامه، اگر حقیقت پایه را به صورت ستونی و پیشبینی مدل را به صورت ردیفی قرار دهید، جدول زیر که ماتریس سردرگمی نامیده میشود، نتیجه میشود:
| مثبت واقعی | منفی واقعی |
---|
مثبت پیش بینی کرد | مثبت واقعی (TP) : یک ایمیل هرزنامه که به درستی به عنوان ایمیل هرزنامه طبقه بندی شده است. اینها پیام های اسپم هستند که به طور خودکار به پوشه اسپم ارسال می شوند. | مثبت کاذب (FP) : یک ایمیل بدون هرزنامه که به اشتباه به عنوان هرزنامه طبقه بندی شده است. اینها ایمیل های قانونی هستند که در پوشه اسپم جمع می شوند. |
---|
منفی پیش بینی کرد | منفی کاذب (FN) : یک ایمیل هرزنامه که به اشتباه به عنوان غیر هرزنامه طبقه بندی شده است. اینها ایمیلهای هرزنامهای هستند که توسط فیلتر هرزنامه دستگیر نمیشوند و به صندوق ورودی راه پیدا میکنند. | منفی واقعی (TN) : یک ایمیل بدون هرزنامه که به درستی به عنوان غیر هرزنامه طبقه بندی شده است. اینها ایمیل های قانونی هستند که مستقیماً به صندوق ورودی ارسال می شوند. |
---|
توجه داشته باشید که مجموع در هر ردیف، بدون در نظر گرفتن اعتبار، تمام مثبت های پیش بینی شده (TP + FP) و همه منفی های پیش بینی شده (FN + TN) را نشان می دهد. در عین حال، مجموع در هر ستون، تمام مثبت های واقعی (TP + FN) و همه منفی های واقعی (FP + TN) را بدون توجه به طبقه بندی مدل نشان می دهد.
وقتی مجموع موارد مثبت واقعی به مجموع موارد منفی واقعی نزدیک نباشد، مجموعه داده نامتعادل می شود. نمونهای از مجموعه داده نامتعادل ممکن است مجموعهای از هزاران عکس از ابرها باشد، که در آن نوع ابر نادری که به آن علاقه دارید، مثلاً ابرهای ولوتوس، فقط چند بار ظاهر میشود.
تأثیر آستانه بر مثبت و منفی درست و غلط
آستانه های مختلف معمولاً به تعداد متفاوتی از موارد مثبت درست و غلط و منفی درست و غلط منجر می شود. ویدئوی زیر دلیل این موضوع را توضیح می دهد.
سعی کنید خود آستانه را تغییر دهید.
این ویجت شامل سه مجموعه داده اسباب بازی است:
- جدا شده ، که در آن مثالهای مثبت و مثالهای منفی عموماً به خوبی متمایز میشوند، و بیشتر نمونههای مثبت امتیاز بیشتری نسبت به نمونههای منفی دارند.
- جدا نشده ، که در آن بسیاری از مثالهای مثبت نمرات کمتری نسبت به نمونههای منفی دارند و بسیاری از مثالهای منفی نمرات بالاتری نسبت به نمونههای مثبت دارند.
- نامتعادل ، فقط شامل چند نمونه از کلاس مثبت است.
درک خود را بررسی کنید
1. یک مدل طبقه بندی فیشینگ یا بدافزار را تصور کنید که در آن وب سایت های فیشینگ و بدافزار در کلاس با برچسب 1 (درست) و وب سایت های بی ضرر در کلاس با برچسب 0 (نادرست) قرار دارند. این مدل به اشتباه یک وب سایت قانونی را به عنوان بدافزار طبقه بندی می کند. اسم این چیه؟
مثبت کاذب
یک مثال منفی (سایت قانونی) به اشتباه به عنوان نمونه مثبت (سایت بدافزار) طبقه بندی شده است.
یک مثبت واقعی
یک نکته مثبت واقعی یک سایت بدافزار است که به درستی به عنوان بدافزار طبقه بندی شده است.
منفی کاذب
منفی کاذب یک سایت بدافزار است که به اشتباه به عنوان یک سایت قانونی طبقه بندی شده است.
یک منفی واقعی
یک منفی واقعی یک سایت قانونی است که به درستی به عنوان یک سایت قانونی طبقه بندی شده است.
2. به طور کلی با افزایش آستانه طبقه بندی، تعداد موارد مثبت کاذب چه اتفاقی می افتد؟ در مورد نکات مثبت واقعی چطور؟ با نوار لغزنده بالا آزمایش کنید.
مثبت و نادرست هر دو کاهش می یابد.
با افزایش آستانه، مدل احتمالاً در مجموع موارد مثبت کمتری را پیشبینی میکند، هم درست و هم نادرست. یک طبقهبندی کننده هرزنامه با آستانه 0.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 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-05-22 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-05-22 بهوقت ساعت هماهنگ جهانی."],[],[],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)"]]