{"id":529,"date":"2020-10-06T07:27:49","date_gmt":"2020-10-06T07:27:49","guid":{"rendered":"http:\/\/feellikelearning.com\/?p=529"},"modified":"2020-11-27T09:03:35","modified_gmt":"2020-11-27T09:03:35","slug":"cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/","title":{"rendered":"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie"},"content":{"rendered":"\n<p>ROC &#8211; Receiver operating characteristic curve<br>AUC &#8211; Area Under the ROC Curve<\/p>\n\n\n\n<p>\u672c\u6587\u4e0d\u6df1\u5165\u8ba8\u8bbaROC\/AUC\u7684\u610f\u4e49\uff0c\u53ea\u662ffocus\u5728\u7528scikit-learn\u5e94\u7528\u4e0a\u3002\u4ee5\u540e\u6211\u4f1a\u5199\u4e00\u4e0b\u81ea\u5df1\u7684\u7406\u89e3\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6709\u4e9b\u8d44\u6599<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/developers.google.com\/machine-learning\/crash-course\/classification\/roc-and-auc\n<\/div><\/figure>\n\n\n\n<p>\u8fd9\u4e2a\u89c6\u9891\u89e3\u91ca\u7684\u7279\u522b\u597d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"ROC Curves and Area Under the Curve (AUC) Explained\" width=\"1130\" height=\"636\" src=\"https:\/\/www.youtube.com\/embed\/OAl6eAyP-yo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u4e3apython\u4ee3\u7801\u3002roc_curve\u53ef\u4ee5take numpy arrays\u3002\u4e00\u822c\u6570\u636e\u90fd\u5728pandas dataframe\u91cc\u5904\u7406\u597d\u3002\u6240\u4ee5\u8fd9\u4e2a\u8fd9\u4e2a\u573a\u666f\u573a\u666f\u4e3a\u4f8b\u5b50<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn import metrics\n\nfpr, tpr, thresholds = metrics.roc_curve(df['label'].to_numpy(), df['prediction'].to_numpy(), pos_label=2)\nauc = metrics.auc(fpr, tpr)\nprint(f'auc = {auc}')<\/code><\/pre>\n\n\n\n<p>ROC\u7684\u7ebf\u4e5f\u53ef\u4ee5\u7528matplotlib\u753b\u51fa\u6765<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import matplotlib.pyplot as plt\n\nplt.plot(fpr, tpr)\nplt.xlabel('fpr')\nplt.ylabel('tpr')\nplt.title('ROC \/ AUC')<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"400\" height=\"259\" src=\"http:\/\/feellikelearning.com\/wp-content\/uploads\/2020\/10\/image.png\" alt=\"\" class=\"wp-image-532\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>ROC &#8211; Receiver operating characteristic curveAUC &#8211; Area Under the ROC Curve \u672c\u6587\u4e0d\u6df1\u5165\u8ba8\u8bbaROC\/AUC\u7684\u610f\u4e49\uff0c\u53ea\u662ffocus\u5728\u7528scikit-learn\u5e94\u7528\u4e0a\u3002\u4ee5\u540e\u6211\u4f1a\u5199\u4e00\u4e0b\u81ea\u5df1\u7684\u7406\u89e3\u3002 \u8fd9\u91cc\u6709\u4e9b\u8d44\u6599<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie | Feel Like Learning<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie | Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"ROC &#8211; Receiver operating characteristic curveAUC &#8211; Area Under the ROC Curve \u672c\u6587\u4e0d\u6df1\u5165\u8ba8\u8bbaROC\/AUC\u7684\u610f\u4e49\uff0c\u53ea\u662ffocus\u5728\u7528scikit-learn\u5e94\u7528\u4e0a\u3002\u4ee5\u540e\u6211\u4f1a\u5199\u4e00\u4e0b\u81ea\u5df1\u7684\u7406\u89e3\u3002 \u8fd9\u91cc\u6709\u4e9b\u8d44\u6599\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-06T07:27:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-27T09:03:35+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/feellikelearning.com\/wp-content\/uploads\/2020\/10\/image.png\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#article\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant\"},\"author\":{\"name\":\"feellikelearning\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"headline\":\"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie\",\"datePublished\":\"2020-10-06T07:27:49+00:00\",\"dateModified\":\"2020-11-27T09:03:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant\"},\"wordCount\":56,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant\",\"url\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant\",\"name\":\"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie | Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/#website\"},\"datePublished\":\"2020-10-06T07:27:49+00:00\",\"dateModified\":\"2020-11-27T09:03:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/#website\",\"url\":\"https:\/\/feellikelearning.com\/\",\"name\":\"Feel Like Learning\",\"description\":\"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230\",\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"logo\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie | Feel Like Learning","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant","og_locale":"en_US","og_type":"article","og_title":"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie | Feel Like Learning","og_description":"ROC &#8211; Receiver operating characteristic curveAUC &#8211; Area Under the ROC Curve \u672c\u6587\u4e0d\u6df1\u5165\u8ba8\u8bbaROC\/AUC\u7684\u610f\u4e49\uff0c\u53ea\u662ffocus\u5728\u7528scikit-learn\u5e94\u7528\u4e0a\u3002\u4ee5\u540e\u6211\u4f1a\u5199\u4e00\u4e0b\u81ea\u5df1\u7684\u7406\u89e3\u3002 \u8fd9\u91cc\u6709\u4e9b\u8d44\u6599","og_url":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant","og_site_name":"Feel Like Learning","article_published_time":"2020-10-06T07:27:49+00:00","article_modified_time":"2020-11-27T09:03:35+00:00","og_image":[{"url":"http:\/\/feellikelearning.com\/wp-content\/uploads\/2020\/10\/image.png"}],"author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#article","isPartOf":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant"},"author":{"name":"feellikelearning","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"headline":"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie","datePublished":"2020-10-06T07:27:49+00:00","dateModified":"2020-11-27T09:03:35+00:00","mainEntityOfPage":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant"},"wordCount":56,"commentCount":0,"publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#respond"]}]},{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant","url":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant","name":"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie | Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/#website"},"datePublished":"2020-10-06T07:27:49+00:00","dateModified":"2020-11-27T09:03:35+00:00","breadcrumb":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/06\/cn-how-to-use-scikit-learn-to-compute-roc-auc-for-binary-classifiers\/?variant=zh-hant#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/"},{"@type":"ListItem","position":2,"name":"\u600e\u6837\u7528scikit-learn\u8ba1\u7b97\u5206\u7c7b\u5668\u7684ROC, AUC? | How to use scikit-learn to compute ROC, AUC for binary classifie"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/#website","url":"https:\/\/feellikelearning.com\/","name":"Feel Like Learning","description":"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230","publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","caption":"feellikelearning"},"logo":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/"},"url":"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/529"}],"collection":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/comments?post=529"}],"version-history":[{"count":4,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":763,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/529\/revisions\/763"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}