{"id":383552,"date":"2024-06-29T04:58:26","date_gmt":"2024-06-29T04:58:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=383552"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=383552","title":{"rendered":"<span>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c ROC-\u043a\u0440\u0438\u0432\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0442\u0435 ROC curve machine learning, \u0442\u043e \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044f \u0432\u044b\u0434\u0430\u0441\u0442 \u0432\u0430\u043c \u0442\u0430\u043a\u043e\u0439 \u043e\u0442\u0432\u0435\u0442: <em>\u041a\u0440\u0438\u0432\u0430\u044f \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u043f\u0440\u0438\u0451\u043c\u043d\u0438\u043a\u0430, \u0438\u043b\u0438 ROC-\u043a\u0440\u0438\u0432\u0430\u044f, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0435\u0451 \u043f\u043e\u0440\u043e\u0433\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f.<\/em><\/p>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u043e \u0447\u0430\u0441\u0442\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 ROC-\u043a\u0440\u0438\u0432\u043e\u0439: <em>ROC-\u043a\u0440\u0438\u0432\u0430\u044f \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u043e\u0440\u043e\u0433\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/em>. \u041d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u044d\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0441\u0431\u0438\u0442\u044c \u0441 \u0442\u043e\u043b\u043a\u0443. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e ROC-\u043a\u0440\u0438\u0432\u044b\u0445.<\/p>\n<h3>\u0427\u0442\u043e \u0437\u0430 \u0447\u0435\u0440\u0442\u043e\u0432\u0449\u0438\u043d\u0430 \u044d\u0442\u0430 ROC-\u043a\u0440\u0438\u0432\u0430\u044f?<\/h3>\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c ROC-\u043a\u0440\u0438\u0432\u0443\u044e: \u043e\u043d\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 (TPR, \u0438\u043b\u0438 true positives rate \u2014 \u0434\u043e\u043b\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432) \u0438 \u0435\u0451 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0441\u0442\u044c\u044e (\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0434\u043e\u043b\u0435\u0439 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432: 1-FPR).<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u043e\u0432\u044c\u0451\u043c \u044d\u0442\u0443 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e. TPR, \u0438\u043b\u0438 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043d\u0430 \u0432\u0441\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"TPR=TP\/P\" alt=\"TPR=TP\/P\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b96\/2f8\/763\/b962f87634ab0be50027a930a1915833.svg\" width=\"121\" height=\"22\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"P:= Positives\" alt=\"P:= Positives\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/200\/03c\/496\/20003c4967adb5071842af3268733a2e.svg\" width=\"126\" height=\"17\"\/><\/p>\n<p>FPR \u2014 \u0434\u043e\u043b\u044f \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, false positives rate. \u042d\u0442\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f\u043c\u0438 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432, \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0451\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435), \u0438 \u0432\u0441\u0435\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438. \u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"FPR = FP\/N\" alt=\"FPR = FP\/N\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5d1\/426\/3c7\/5d14263c71a0da67c0e81236c0f5b01f.svg\" width=\"125\" height=\"22\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"N := Negatives\" alt=\"N := Negatives\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e72\/81d\/8e8\/e7281d8e8ba38563d1adad7188e0efa3.svg\" width=\"135\" height=\"20\"\/><\/p>\n<p><em>\u041e\u0431\u043e\u0431\u0449\u0430\u044f:<\/em><strong><em> <\/em><\/strong>\u0432\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043e\u043b\u044f\u043c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u0430\u0445 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f. \u041c\u043e\u0434\u0435\u043b\u044c \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0440\u043e\u0433 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0445 \u043a \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u043e\u0440\u043e\u0433\u0430\u043c\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u044f \u0442\u043e\u043b\u043a\u0430\u043b\u0430 \u043a \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0440\u043e\u043b\u0438 \u043f\u043e\u0440\u043e\u0433\u043e\u0432 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f. \u041c\u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0430 \u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/84e\/3d4\/943\/84e3d494310fb0be850da6449f7faafa.png\" alt=\"\u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0445 \u043c\u044b\u0448\u0435\u0439\" title=\"\u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0445 \u043c\u044b\u0448\u0435\u0439\" width=\"904\" height=\"623\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/84e\/3d4\/943\/84e3d494310fb0be850da6449f7faafa.png\"\/><figcaption>\u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0445 \u043c\u044b\u0448\u0435\u0439<\/figcaption><\/figure>\n<p>\u0421 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0434\u043e \u043c\u0435\u043d\u044f \u0434\u043e\u0448\u043b\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u043e\u043b\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u0430, \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u043b\u044f \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0438\u0436\u0435.<\/p>\n<p>\u041f\u043e\u0440\u043e\u0433 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 T (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 0 \u0438 1), \u0441\u043b\u0443\u0436\u0438\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0438 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441 \u043c\u0435\u0436\u0434\u0443 TPR \u0438 FPR. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p><strong>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ROC-\u043a\u0440\u0438\u0432\u043e\u0439<\/strong><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:<\/p>\n<ol>\n<li>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e drawdata \u0434\u043b\u044f Jupyter<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a pandas<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u043a \u0434\u0430\u043d\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0440\u043e\u0433\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c ROC-\u043a\u0440\u0438\u0432\u0443\u044e<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u00a0\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/strong><\/p>\n<pre><code class=\"python\">from drawdata import draw_scatter import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score, precision_recall_curve,precision_score, plot_roc_curve<\/code><\/pre>\n<p><strong>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u043a\u0435\u0442\u0430 drawdata \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u043d\u043e\u0442\u043e\u0432 Jupyter<\/strong><\/p>\n<pre><code class=\"python\">draw_scatter()<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f03\/a70\/3aa\/f03a703aaf88075279fe7005523d089f.png\" width=\"949\" height=\"693\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f03\/a70\/3aa\/f03a703aaf88075279fe7005523d089f.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a pandas<\/strong><\/p>\n<pre><code class=\"python\">df = pd.read_csv(\".\/data.csv\")<\/code><\/pre>\n<p><strong>\u041f\u043e\u0434\u0431\u0435\u0440\u0451\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u043a \u0434\u0430\u043d\u043d\u044b\u043c<\/strong><\/p>\n<pre><code class=\"python\">def get_fp_tp(y, proba, threshold): \"\"\"\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043b\u0435\u0439 \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445.\"\"\" # \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a: https:\/\/towardsdatascience.com\/roc-curve-explained-50acab4f7bd8 # \u0420\u0430\u0437\u043d\u043e\u0441\u0438\u043c \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c pred = pd.Series(np.where(proba>=threshold, 1, 0),                  dtype='category') pred.cat.set_categories([0,1], inplace=True) # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a confusion_matrix = pred.groupby([y, pred]).size().unstack()\\                            .rename(columns={0: 'pred_0',                                         1: 'pred_1'},                                    index={0: 'actual_0',                                           1: 'actual_1'}) false_positives = confusion_matrix.loc['actual_0', 'pred_1'] true_positives = confusion_matrix.loc['actual_1', 'pred_1'] return false_positives, true_positives # train \/ test split \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 X = df[[\"x\", \"y\"]].values Y = df[\"z\"].values X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=42) y_test = np.array([1 if p==\"a\" else 0 for p in y_test]) y_train = np.array([1 if p==\"a\" else 0 for p in y_train]) # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u043e\u0434\u0435\u043b\u044c lgr = LogisticRegression() lgr.fit(X_train, y_train)<\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438<\/strong><\/p>\n<pre><code class=\"python\">y_hat = lgr.predict_proba(X_test)[:,1]<\/code><\/pre>\n<p><strong>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/strong><\/p>\n<pre><code class=\"python\">thresholds = np.linspace(0,1,100)<\/code><\/pre>\n<p><strong>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c ROC-\u043a\u0440\u0438\u0432\u0443\u044e<\/strong><\/p>\n<pre><code class=\"python\"># defining fpr and tpr tpr = [] fpr = [] # \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 positives = np.sum(y_test==1) negatives = np.sum(y_test==0) # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u043e\u0436\u043d\u043e \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432  for th in thresholds: fp,tp = get_fp_tp(y_test, y_hat, th) tpr.append(tp\/positives) fpr.append(fp\/negatives) plt.plot([0, 1], [0, 1], linestyle='--', lw=2, color='r',label='Random', alpha=.8) plt.plot(fpr,tpr, label=\"ROC Curve\",color=\"blue\") plt.text(0.5, 0.5, \"varying threshold scores (0-1)\", rotation=0, size=12,ha=\"center\", va=\"center\",bbox=dict(boxstyle=\"rarrow\")) plt.xlabel(\"False Positve Rate\") plt.ylabel(\"True Positive Rate\") plt.legend() plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/42a\/fd1\/d0b\/42afd1d0b2c827ad1bd3ea70390cf318.png\" alt=\"\" title=\"\" width=\"393\" height=\"268\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42a\/fd1\/d0b\/42afd1d0b2c827ad1bd3ea70390cf318.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b<\/strong><\/p>\n<p>\u0418\u0437\u043c\u0435\u043d\u044f\u044f \u043f\u043e\u0440\u043e\u0433, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445, \u0442\u0430\u043a \u0438 \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u0439. \u0412 \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0440\u043e\u0433 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0432\u0438\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u043e\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043b\u0438\u0436\u0435 \u043a 1, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u043e\u043b\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u043d\u0438\u0436\u043d\u0435\u043c \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439.<\/p>\n<p>\u041a\u0430\u043a \u043d\u0430\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0439 \u043f\u043e\u0440\u043e\u0433?<\/p>\n<blockquote>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u0442 \u043f\u043e\u0440\u043e\u0433, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0438\u0437 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u043b\u043e\u0436\u043d\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u0439 (1-FPR).<\/p>\n<\/blockquote>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439: \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u0442\u043e\u0447\u043a\u0438, \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0439 \u043a \u043b\u0435\u0432\u043e\u043c\u0443 \u0432\u0435\u0440\u0445\u043d\u0435\u043c\u0443 \u0443\u0433\u043b\u0443 ROC-\u043a\u0440\u0438\u0432\u043e\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 <a href=\"https:\/\/stats.stackexchange.com\/questions\/123124\/how-to-determine-the-optimal-threshold-for-a-classifier-and-generate-roc-curve#:~:text=A%20simple%20method%20is%20to,thresholds%20like%20financial%20costs,%20etc.&amp;text=Choose%20the%20point%20closest%20to,corner%20of%20your%20ROC%20space.\">\u0438\u043c\u0435\u044e\u0442<\/a> \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0432\u0435\u0441. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u0442\u0430\u043a\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u0439 \u0432\u0435\u0441\u043e\u043c\u0435\u0435, \u0447\u0435\u043c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b \u043e ROC-\u043a\u0440\u0438\u0432\u043e\u0439<\/h3>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0432 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u043e\u0446\u0435\u043d\u043e\u0447\u043d\u044b\u0445 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u0443\u0437\u043d\u0430\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 ROC-\u043a\u0440\u0438\u0432\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u043f\u043e\u0440\u043e\u0433\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ROC-\u043a\u0440\u0438\u0432\u044b\u0435 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u043e\u0432 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/582756\/\"> https:\/\/habr.com\/ru\/articles\/582756\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0442\u0435 ROC curve machine learning, \u0442\u043e \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044f \u0432\u044b\u0434\u0430\u0441\u0442 \u0432\u0430\u043c \u0442\u0430\u043a\u043e\u0439 \u043e\u0442\u0432\u0435\u0442: <em>\u041a\u0440\u0438\u0432\u0430\u044f \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u043f\u0440\u0438\u0451\u043c\u043d\u0438\u043a\u0430, \u0438\u043b\u0438 ROC-\u043a\u0440\u0438\u0432\u0430\u044f, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0435\u0451 \u043f\u043e\u0440\u043e\u0433\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f.<\/em><\/p>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u043e \u0447\u0430\u0441\u0442\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 ROC-\u043a\u0440\u0438\u0432\u043e\u0439: <em>ROC-\u043a\u0440\u0438\u0432\u0430\u044f \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u043e\u0440\u043e\u0433\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/em>. \u041d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u044d\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0441\u0431\u0438\u0442\u044c \u0441 \u0442\u043e\u043b\u043a\u0443. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e ROC-\u043a\u0440\u0438\u0432\u044b\u0445.<\/p>\n<h3>\u0427\u0442\u043e \u0437\u0430 \u0447\u0435\u0440\u0442\u043e\u0432\u0449\u0438\u043d\u0430 \u044d\u0442\u0430 ROC-\u043a\u0440\u0438\u0432\u0430\u044f?<\/h3>\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c ROC-\u043a\u0440\u0438\u0432\u0443\u044e: \u043e\u043d\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 (TPR, \u0438\u043b\u0438 true positives rate \u2014 \u0434\u043e\u043b\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432) \u0438 \u0435\u0451 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0441\u0442\u044c\u044e (\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0434\u043e\u043b\u0435\u0439 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432: 1-FPR).<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u043e\u0432\u044c\u0451\u043c \u044d\u0442\u0443 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e. TPR, \u0438\u043b\u0438 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043d\u0430 \u0432\u0441\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p>FPR \u2014 \u0434\u043e\u043b\u044f \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, false positives rate. \u042d\u0442\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f\u043c\u0438 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432, \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0451\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435), \u0438 \u0432\u0441\u0435\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438. \u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<p><em>\u041e\u0431\u043e\u0431\u0449\u0430\u044f:<\/em><strong><em> <\/em><\/strong>\u0432\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043e\u043b\u044f\u043c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u0430\u0445 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f. \u041c\u043e\u0434\u0435\u043b\u044c \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0440\u043e\u0433 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0445 \u043a \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u043e\u0440\u043e\u0433\u0430\u043c\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u044f \u0442\u043e\u043b\u043a\u0430\u043b\u0430 \u043a \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0440\u043e\u043b\u0438 \u043f\u043e\u0440\u043e\u0433\u043e\u0432 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f. \u041c\u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0430 \u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430:<\/p>\n<figure class=\"full-width\"><figcaption>\u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0445 \u043c\u044b\u0448\u0435\u0439<\/figcaption><\/figure>\n<p>\u0421 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0434\u043e \u043c\u0435\u043d\u044f \u0434\u043e\u0448\u043b\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u043e\u043b\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u0430, \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u043b\u044f \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0438\u0436\u0435.<\/p>\n<p>\u041f\u043e\u0440\u043e\u0433 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 T (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 0 \u0438 1), \u0441\u043b\u0443\u0436\u0438\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0438 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441 \u043c\u0435\u0436\u0434\u0443 TPR \u0438 FPR. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p><strong>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ROC-\u043a\u0440\u0438\u0432\u043e\u0439<\/strong><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:<\/p>\n<ol>\n<li>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e drawdata \u0434\u043b\u044f Jupyter<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a pandas<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u043a \u0434\u0430\u043d\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0440\u043e\u0433\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c ROC-\u043a\u0440\u0438\u0432\u0443\u044e<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u00a0\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/strong><\/p>\n<pre><code class=\"python\">from drawdata import draw_scatter import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score, precision_recall_curve,precision_score, plot_roc_curve<\/code><\/pre>\n<p><strong>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u043a\u0435\u0442\u0430 drawdata \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u043d\u043e\u0442\u043e\u0432 Jupyter<\/strong><\/p>\n<pre><code class=\"python\">draw_scatter()<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a pandas<\/strong><\/p>\n<pre><code class=\"python\">df = pd.read_csv(\".\/data.csv\")<\/code><\/pre>\n<p><strong>\u041f\u043e\u0434\u0431\u0435\u0440\u0451\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u043a \u0434\u0430\u043d\u043d\u044b\u043c<\/strong><\/p>\n<pre><code class=\"python\">def get_fp_tp(y, proba, threshold): \"\"\"\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043b\u0435\u0439 \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445.\"\"\" # \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a: https:\/\/towardsdatascience.com\/roc-curve-explained-50acab4f7bd8 # \u0420\u0430\u0437\u043d\u043e\u0441\u0438\u043c \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c pred = pd.Series(np.where(proba>=threshold, 1, 0),                  dtype='category') pred.cat.set_categories([0,1], inplace=True) # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a confusion_matrix = pred.groupby([y, pred]).size().unstack()\\                            .rename(columns={0: 'pred_0',                                         1: 'pred_1'},                                    index={0: 'actual_0',                                           1: 'actual_1'}) false_positives = confusion_matrix.loc['actual_0', 'pred_1'] true_positives = confusion_matrix.loc['actual_1', 'pred_1'] return false_positives, true_positives # train \/ test split \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 X = df[[\"x\", \"y\"]].values Y = df[\"z\"].values X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=42) y_test = np.array([1 if p==\"a\" else 0 for p in y_test]) y_train = np.array([1 if p==\"a\" else 0 for p in y_train]) # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u043e\u0434\u0435\u043b\u044c lgr = LogisticRegression() lgr.fit(X_train, y_train)<\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438<\/strong><\/p>\n<pre><code class=\"python\">y_hat = lgr.predict_proba(X_test)[:,1]<\/code><\/pre>\n<p><strong>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/strong><\/p>\n<pre><code class=\"python\">thresholds = np.linspace(0,1,100)<\/code><\/pre>\n<p><strong>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c ROC-\u043a\u0440\u0438\u0432\u0443\u044e<\/strong><\/p>\n<pre><code class=\"python\"># defining fpr and tpr tpr = [] fpr = [] # \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 positives = np.sum(y_test==1) negatives = np.sum(y_test==0) # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u043e\u0436\u043d\u043e \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432  for th in thresholds: fp,tp = get_fp_tp(y_test, y_hat, th) tpr.append(tp\/positives) fpr.append(fp\/negatives) plt.plot([0, 1], [0, 1], linestyle='--', lw=2, color='r',label='Random', alpha=.8) plt.plot(fpr,tpr, label=\"ROC Curve\",color=\"blue\") plt.text(0.5, 0.5, \"varying threshold scores (0-1)\", rotation=0, size=12,ha=\"center\", va=\"center\",bbox=dict(boxstyle=\"rarrow\")) plt.xlabel(\"False Positve Rate\") plt.ylabel(\"True Positive Rate\") plt.legend() plt.show()<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b<\/strong><\/p>\n<p>\u0418\u0437\u043c\u0435\u043d\u044f\u044f \u043f\u043e\u0440\u043e\u0433, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445, \u0442\u0430\u043a \u0438 \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u0439. \u0412 \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0440\u043e\u0433 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0432\u0438\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u043e\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043b\u0438\u0436\u0435 \u043a 1, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u043e\u043b\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u043d\u0438\u0436\u043d\u0435\u043c \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439.<\/p>\n<p>\u041a\u0430\u043a \u043d\u0430\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0439 \u043f\u043e\u0440\u043e\u0433?<\/p>\n<blockquote>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u0442 \u043f\u043e\u0440\u043e\u0433, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0438\u0437 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u043b\u043e\u0436\u043d\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u0439 (1-FPR).<\/p>\n<\/blockquote>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439: \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u0442\u043e\u0447\u043a\u0438, \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0439 \u043a \u043b\u0435\u0432\u043e\u043c\u0443 \u0432\u0435\u0440\u0445\u043d\u0435\u043c\u0443 \u0443\u0433\u043b\u0443 ROC-\u043a\u0440\u0438\u0432\u043e\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 <a href=\"https:\/\/stats.stackexchange.com\/questions\/123124\/how-to-determine-the-optimal-threshold-for-a-classifier-and-generate-roc-curve#:~:text=A%20simple%20method%20is%20to,thresholds%20like%20financial%20costs,%20etc.&amp;text=Choose%20the%20point%20closest%20to,corner%20of%20your%20ROC%20space.\">\u0438\u043c\u0435\u044e\u0442<\/a> \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0432\u0435\u0441. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u0442\u0430\u043a\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u0439 \u0432\u0435\u0441\u043e\u043c\u0435\u0435, \u0447\u0435\u043c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b \u043e ROC-\u043a\u0440\u0438\u0432\u043e\u0439<\/h3>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0432 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u043e\u0446\u0435\u043d\u043e\u0447\u043d\u044b\u0445 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u0443\u0437\u043d\u0430\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 ROC-\u043a\u0440\u0438\u0432\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u043f\u043e\u0440\u043e\u0433\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ROC-\u043a\u0440\u0438\u0432\u044b\u0435 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u043e\u0432 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/582756\/\"> https:\/\/habr.com\/ru\/articles\/582756\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-383552","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=383552"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383552\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=383552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=383552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=383552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}