{"id":1138725,"date":"2025-01-08T22:02:51","date_gmt":"2025-01-08T14:02:51","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1138725.html"},"modified":"2025-01-08T22:02:54","modified_gmt":"2025-01-08T14:02:54","slug":"roc%e4%ba%8c%e5%88%86%e7%b1%bb%e6%9b%b2%e7%ba%bf%e6%95%b0%e6%8d%aepython%e5%a6%82%e4%bd%95%e6%94%b6%e9%9b%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1138725.html","title":{"rendered":"roc\u4e8c\u5206\u7c7b\u66f2\u7ebf\u6570\u636epython\u5982\u4f55\u6536\u96c6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25102233\/38198fae-5995-4772-874c-fafcb7b62cae.webp\" alt=\"roc\u4e8c\u5206\u7c7b\u66f2\u7ebf\u6570\u636epython\u5982\u4f55\u6536\u96c6\" \/><\/p>\n<p><p> <strong>ROC\u4e8c\u5206\u7c7b\u66f2\u7ebf\u6570\u636e\u5728Python\u4e2d\u5982\u4f55\u6536\u96c6<\/strong>\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528<code>scikit-learn<\/code>\u5e93\u4e2d\u7684\u51fd\u6570\u3001\u624b\u52a8\u8ba1\u7b97TPR\u548cFPR\u3001\u5c06\u7ed3\u679c\u53ef\u89c6\u5316\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528<code>scikit-learn<\/code>\u5e93\u4e2d\u7684\u51fd\u6570\u6765\u6536\u96c6ROC\u4e8c\u5206\u7c7b\u66f2\u7ebf\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528<code>scikit-learn<\/code>\u5e93\u4e2d\u7684\u51fd\u6570\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5<\/strong>\uff0c\u56e0\u4e3a\u5b83\u7b80\u5316\u4e86\u8bb8\u591a\u6b65\u9aa4\u5e76\u4e14\u975e\u5e38\u76f4\u89c2\u3002<\/p>\n<\/p>\n<p><p><strong>\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u51c6\u5907<\/strong>\uff1a\u9996\u5148\u9700\u8981\u51c6\u5907\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u5e94\u5305\u62ec\u7279\u5f81\u548c\u6807\u7b7e\u3002<\/li>\n<li><strong>\u6a21\u578b\u8bad\u7ec3<\/strong>\uff1a\u4f7f\u7528<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7b97\u6cd5\u6765\u8bad\u7ec3\u6a21\u578b\u3002<\/li>\n<li><strong>\u9884\u6d4b\u6982\u7387<\/strong>\uff1a\u4f7f\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u6765\u9884\u6d4b\u6d4b\u8bd5\u6570\u636e\u7684\u6982\u7387\u3002<\/li>\n<li><strong>\u8ba1\u7b97ROC\u66f2\u7ebf\u6570\u636e<\/strong>\uff1a\u4f7f\u7528<code>scikit-learn<\/code>\u7684<code>roc_curve<\/code>\u51fd\u6570\u6765\u8ba1\u7b97ROC\u66f2\u7ebf\u6240\u9700\u7684TPR\u548cFPR\u3002<\/li>\n<li><strong>\u7ed8\u5236ROC\u66f2\u7ebf<\/strong>\uff1a\u4f7f\u7528Matplotlib\u6216\u5176\u4ed6\u53ef\u89c6\u5316\u5e93\u6765\u7ed8\u5236ROC\u66f2\u7ebf\u3002<\/li>\n<\/ol>\n<p><h3>\u4e00\u3001\u6570\u636e\u51c6\u5907<\/h3>\n<\/p>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u4efb\u52a1\u4e2d\uff0c\u6570\u636e\u51c6\u5907\u662f\u7b2c\u4e00\u6b65\u3002\u6570\u636e\u901a\u5e38\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u3002\u8bad\u7ec3\u96c6\u7528\u4e8e\u8bad\u7ec3\u6a21\u578b\uff0c\u6d4b\u8bd5\u96c6\u7528\u4e8e\u8bc4\u4f30\u6a21\u578b\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.datasets import make_classification<\/p>\n<p>from sklearn.model_selection import tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n_test_split<\/p>\n<h2><strong>\u751f\u6210\u6a21\u62df\u6570\u636e\u96c6<\/strong><\/h2>\n<p>X, y = make_classification(n_samples=1000, n_features=20, random_state=42)<\/p>\n<h2><strong>\u5206\u5272\u6570\u636e\u96c6\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong><\/h2>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u6a21\u578b\u8bad\u7ec3<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u9009\u62e9\u4e00\u4e2a\u4e8c\u5206\u7c7b\u6a21\u578b\u5e76\u4f7f\u7528\u8bad\u7ec3\u96c6\u6570\u636e\u8fdb\u884c\u8bad\u7ec3\u3002\u8fd9\u91cc\u6211\u4eec\u9009\u62e9\u903b\u8f91\u56de\u5f52\u6a21\u578b\u4f5c\u4e3a\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.linear_model import LogisticRegression<\/p>\n<h2><strong>\u5b9e\u4f8b\u5316\u903b\u8f91\u56de\u5f52\u6a21\u578b<\/strong><\/h2>\n<p>model = LogisticRegression()<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X_train, y_train)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u9884\u6d4b\u6982\u7387<\/h3>\n<\/p>\n<p><p>\u8bad\u7ec3\u5b8c\u6a21\u578b\u540e\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u6a21\u578b\u5bf9\u6d4b\u8bd5\u96c6\u6570\u636e\u8fdb\u884c\u9884\u6d4b\uff0c\u5e76\u83b7\u53d6\u9884\u6d4b\u6982\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u9884\u6d4b\u6982\u7387<\/p>\n<p>y_probs = model.predict_proba(X_test)[:, 1]  # \u9009\u62e9\u6b63\u7c7b\u7684\u6982\u7387<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u8ba1\u7b97ROC\u66f2\u7ebf\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<code>scikit-learn<\/code>\u7684<code>roc_curve<\/code>\u51fd\u6570\u6765\u8ba1\u7b97TPR\u548cFPR\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.metrics import roc_curve<\/p>\n<h2><strong>\u8ba1\u7b97TPR\u548cFPR<\/strong><\/h2>\n<p>fpr, tpr, thresholds = roc_curve(y_test, y_probs)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u7ed8\u5236ROC\u66f2\u7ebf<\/h3>\n<\/p>\n<p><p>\u6700\u540e\u4e00\u6b65\u662f\u4f7f\u7528Matplotlib\u6216\u5176\u4ed6\u53ef\u89c6\u5316\u5de5\u5177\u6765\u7ed8\u5236ROC\u66f2\u7ebf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u7ed8\u5236ROC\u66f2\u7ebf<\/strong><\/h2>\n<p>plt.figure()<\/p>\n<p>plt.plot(fpr, tpr, color=&#39;blue&#39;, lw=2, label=&#39;ROC curve&#39;)<\/p>\n<p>plt.plot([0, 1], [0, 1], color=&#39;gray&#39;, lw=2, linestyle=&#39;--&#39;)<\/p>\n<p>plt.xlim([0.0, 1.0])<\/p>\n<p>plt.ylim([0.0, 1.0])<\/p>\n<p>plt.xlabel(&#39;False Positive Rate&#39;)<\/p>\n<p>plt.ylabel(&#39;True Positive Rate&#39;)<\/p>\n<p>plt.title(&#39;Receiver Operating Characteristic (ROC)&#39;)<\/p>\n<p>plt.legend(loc=&quot;lower right&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6df1\u5165\u7406\u89e3ROC\u66f2\u7ebf<\/h3>\n<\/p>\n<p><p><strong>ROC\u66f2\u7ebf\u7684\u6982\u5ff5<\/strong><\/p>\n<\/p>\n<p><p>ROC\u66f2\u7ebf\uff08Receiver Operating Characteristic Curve\uff09\u662f\u7528\u6765\u8bc4\u4ef7\u4e8c\u5206\u7c7b\u6a21\u578b\u6027\u80fd\u7684\u5de5\u5177\u3002\u66f2\u7ebf\u901a\u8fc7\u7ed8\u5236\u5047\u9633\u6027\u7387\uff08False Positive Rate, FPR\uff09\u5bf9\u771f\u9633\u6027\u7387\uff08True Positive Rate, TPR\uff09\u6765\u8868\u73b0\u5206\u7c7b\u5668\u7684\u6027\u80fd\u3002<strong>\u5047\u9633\u6027\u7387\uff08FPR\uff09<\/strong>\u662f\u6307\u9519\u8bef\u5730\u5c06\u8d1f\u7c7b\u5206\u7c7b\u4e3a\u6b63\u7c7b\u7684\u6bd4\u4f8b\uff0c\u800c<strong>\u771f\u9633\u6027\u7387\uff08TPR\uff09<\/strong>\u662f\u6307\u6b63\u786e\u5730\u5c06\u6b63\u7c7b\u5206\u7c7b\u4e3a\u6b63\u7c7b\u7684\u6bd4\u4f8b\u3002<\/p>\n<\/p>\n<p><p><strong>\u7406\u89e3AUC\u503c<\/strong><\/p>\n<\/p>\n<p><p>AUC\uff08Area Under the Curve\uff09\u662fROC\u66f2\u7ebf\u4e0b\u7684\u9762\u79ef\uff0c\u5b83\u7684\u503c\u4ecb\u4e8e0\u548c1\u4e4b\u95f4\uff0c\u8868\u793a\u5206\u7c7b\u5668\u7684\u6027\u80fd\u3002<strong>AUC\u503c\u8d8a\u63a5\u8fd11\uff0c\u5206\u7c7b\u5668\u7684\u6027\u80fd\u8d8a\u597d<\/strong>\u3002\u5982\u679cAUC\u503c\u4e3a0.5\uff0c\u8868\u793a\u5206\u7c7b\u5668\u7684\u6027\u80fd\u4e0e\u968f\u673a\u731c\u6d4b\u76f8\u5f53\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u624b\u52a8\u8ba1\u7b97TPR\u548cFPR<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u4f7f\u7528<code>scikit-learn<\/code>\u8ba1\u7b97TPR\u548cFPR\u975e\u5e38\u65b9\u4fbf\uff0c\u4f46\u4e86\u89e3\u624b\u52a8\u8ba1\u7b97\u7684\u8fc7\u7a0b\u6709\u52a9\u4e8e\u6df1\u5165\u7406\u89e3\u8fd9\u4e9b\u6982\u5ff5\u3002<\/p>\n<\/p>\n<p><p><strong>\u6b65\u9aa4\u5982\u4e0b\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li>\u6392\u5e8f\uff1a\u6839\u636e\u6a21\u578b\u7684\u9884\u6d4b\u6982\u7387\u5bf9\u6837\u672c\u8fdb\u884c\u6392\u5e8f\u3002<\/li>\n<li>\u9608\u503c\uff1a\u9009\u62e9\u4e0d\u540c\u7684\u9608\u503c\u8fdb\u884c\u5206\u7c7b\u3002<\/li>\n<li>\u8ba1\u7b97\uff1a\u8ba1\u7b97\u6bcf\u4e2a\u9608\u503c\u4e0b\u7684TPR\u548cFPR\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u6392\u5e8f<\/strong><\/h2>\n<p>sorted_indices = np.argsort(y_probs)<\/p>\n<p>sorted_y_true = y_test[sorted_indices]<\/p>\n<p>sorted_y_probs = y_probs[sorted_indices]<\/p>\n<h2><strong>\u521d\u59cb\u5316<\/strong><\/h2>\n<p>tpr = []<\/p>\n<p>fpr = []<\/p>\n<h2><strong>\u9608\u503c\u904d\u5386<\/strong><\/h2>\n<p>for threshold in sorted_y_probs:<\/p>\n<p>    tp = fp = tn = fn = 0<\/p>\n<p>    for i in range(len(sorted_y_probs)):<\/p>\n<p>        if sorted_y_probs[i] &gt;= threshold:<\/p>\n<p>            if sorted_y_true[i] == 1:<\/p>\n<p>                tp += 1<\/p>\n<p>            else:<\/p>\n<p>                fp += 1<\/p>\n<p>        else:<\/p>\n<p>            if sorted_y_true[i] == 1:<\/p>\n<p>                fn += 1<\/p>\n<p>            else:<\/p>\n<p>                tn += 1<\/p>\n<p>    tpr.append(tp \/ (tp + fn))<\/p>\n<p>    fpr.append(fp \/ (fp + tn))<\/p>\n<h2><strong>\u8f6c\u6362\u4e3anumpy\u6570\u7ec4<\/strong><\/h2>\n<p>tpr = np.array(tpr)<\/p>\n<p>fpr = np.array(fpr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u6a21\u578b\u6027\u80fd\u8bc4\u4f30<\/h3>\n<\/p>\n<p><p><strong>\u6a21\u578b\u6027\u80fd\u8bc4\u4f30\u7684\u65b9\u6cd5\u6709\u5f88\u591a<\/strong>\uff0cROC\u66f2\u7ebf\u548cAUC\u503c\u53ea\u662f\u5176\u4e2d\u4e4b\u4e00\u3002\u5176\u4ed6\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u6df7\u6dc6\u77e9\u9635\uff08Confusion Matrix\uff09\u3001\u51c6\u786e\u7387\uff08Accuracy\uff09\u3001\u7cbe\u786e\u7387\uff08Precision\uff09\u3001\u53ec\u56de\u7387\uff08Recall\uff09\u548cF1\u5206\u6570\uff08F1 Score\uff09\u3002<\/p>\n<\/p>\n<p><p><strong>\u6df7\u6dc6\u77e9\u9635<\/strong><\/p>\n<\/p>\n<p><p>\u6df7\u6dc6\u77e9\u9635\u662f\u4e00\u79cd\u7528\u4e8e\u63cf\u8ff0\u5206\u7c7b\u6a21\u578b\u6027\u80fd\u7684\u5de5\u5177\u3002\u5b83\u5c55\u793a\u4e86\u9884\u6d4b\u7ed3\u679c\u4e0e\u5b9e\u9645\u7ed3\u679c\u7684\u5bf9\u6bd4\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.metrics import confusion_matrix<\/p>\n<h2><strong>\u8ba1\u7b97\u6df7\u6dc6\u77e9\u9635<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<p>conf_matrix = confusion_matrix(y_test, y_pred)<\/p>\n<p>print(conf_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u51c6\u786e\u7387\u3001\u7cbe\u786e\u7387\u3001\u53ec\u56de\u7387\u548cF1\u5206\u6570<\/strong><\/p>\n<\/p>\n<p><p>\u8fd9\u4e9b\u6307\u6807\u4e5f\u662f\u8bc4\u4f30\u5206\u7c7b\u6a21\u578b\u6027\u80fd\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score<\/p>\n<h2><strong>\u8ba1\u7b97\u5404\u9879\u6307\u6807<\/strong><\/h2>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>precision = precision_score(y_test, y_pred)<\/p>\n<p>recall = recall_score(y_test, y_pred)<\/p>\n<p>f1 = f1_score(y_test, y_pred)<\/p>\n<p>print(f&#39;Accuracy: {accuracy}&#39;)<\/p>\n<p>print(f&#39;Precision: {precision}&#39;)<\/p>\n<p>print(f&#39;Recall: {recall}&#39;)<\/p>\n<p>print(f&#39;F1 Score: {f1}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u6a21\u578b\u4f18\u5316<\/h3>\n<\/p>\n<p><p><strong>\u4e3a\u4e86\u63d0\u9ad8\u6a21\u578b\u6027\u80fd\uff0c\u53ef\u4ee5\u8fdb\u884c\u6a21\u578b\u4f18\u5316<\/strong>\u3002\u5e38\u89c1\u7684\u4f18\u5316\u65b9\u6cd5\u5305\u62ec\u7279\u5f81\u9009\u62e9\u3001\u6570\u636e\u589e\u5f3a\u548c\u8d85\u53c2\u6570\u8c03\u4f18\u3002<\/p>\n<\/p>\n<p><p><strong>\u7279\u5f81\u9009\u62e9<\/strong><\/p>\n<\/p>\n<p><p>\u7279\u5f81\u9009\u62e9\u662f\u6307\u4ece\u6570\u636e\u96c6\u4e2d\u9009\u62e9\u6700\u6709\u52a9\u4e8e\u9884\u6d4b\u7684\u7279\u5f81\uff0c\u4ee5\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.feature_selection import SelectKBest, f_classif<\/p>\n<h2><strong>\u9009\u62e9\u6700\u6709\u52a9\u4e8e\u9884\u6d4b\u7684\u7279\u5f81<\/strong><\/h2>\n<p>selector = SelectKBest(f_classif, k=10)<\/p>\n<p>X_new = selector.fit_transform(X, y)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6570\u636e\u589e\u5f3a<\/strong><\/p>\n<\/p>\n<p><p>\u6570\u636e\u589e\u5f3a\u662f\u6307\u901a\u8fc7\u5bf9\u73b0\u6709\u6570\u636e\u8fdb\u884c\u53d8\u6362\u6765\u751f\u6210\u65b0\u7684\u6570\u636e\uff0c\u4ee5\u63d0\u9ad8\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from imblearn.over_sampling import SMOTE<\/p>\n<h2><strong>\u4f7f\u7528SMOTE\u8fdb\u884c\u6570\u636e\u589e\u5f3a<\/strong><\/h2>\n<p>smote = SMOTE(random_state=42)<\/p>\n<p>X_resampled, y_resampled = smote.fit_resample(X_train, y_train)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8d85\u53c2\u6570\u8c03\u4f18<\/strong><\/p>\n<\/p>\n<p><p>\u8d85\u53c2\u6570\u8c03\u4f18\u662f\u6307\u901a\u8fc7\u8c03\u6574\u6a21\u578b\u7684\u53c2\u6570\u6765\u63d0\u9ad8\u6a21\u578b\u6027\u80fd\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u7f51\u683c\u641c\u7d22\uff08Grid Search\uff09\u548c\u968f\u673a\u641c\u7d22\uff08Random Search\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import GridSearchCV<\/p>\n<h2><strong>\u5b9a\u4e49\u53c2\u6570\u7f51\u683c<\/strong><\/h2>\n<p>param_grid = {<\/p>\n<p>    &#39;C&#39;: [0.1, 1, 10, 100],<\/p>\n<p>    &#39;solver&#39;: [&#39;liblinear&#39;, &#39;saga&#39;]<\/p>\n<p>}<\/p>\n<h2><strong>\u5b9e\u4f8b\u5316GridSearchCV<\/strong><\/h2>\n<p>grid_search = GridSearchCV(LogisticRegression(), param_grid, cv=5)<\/p>\n<h2><strong>\u8fdb\u884c\u7f51\u683c\u641c\u7d22<\/strong><\/h2>\n<p>grid_search.fit(X_train, y_train)<\/p>\n<h2><strong>\u6253\u5370\u6700\u4f18\u53c2\u6570<\/strong><\/h2>\n<p>print(grid_search.best_params_)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728Python\u4e2d\u6536\u96c6\u548c\u7ed8\u5236ROC\u4e8c\u5206\u7c7b\u66f2\u7ebf\u6570\u636e\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\u6570\u636e\u51c6\u5907\u3001\u6a21\u578b\u8bad\u7ec3\u3001\u9884\u6d4b\u6982\u7387\u3001\u8ba1\u7b97ROC\u66f2\u7ebf\u6570\u636e\u548c\u7ed8\u5236ROC\u66f2\u7ebf\u3002\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u4ecb\u7ecd\u4e86\u624b\u52a8\u8ba1\u7b97TPR\u548cFPR\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5176\u4ed6\u6a21\u578b\u6027\u80fd\u8bc4\u4f30\u6307\u6807\u548c\u6a21\u578b\u4f18\u5316\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u548c\u8bc4\u4f30\u60a8\u7684\u4e8c\u5206\u7c7b\u6a21\u578b\uff0c\u5e76\u8fdb\u4e00\u6b65\u4f18\u5316\u5176\u6027\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u751f\u6210ROC\u66f2\u7ebf\u6570\u636e\uff1f<\/strong><br \/>\u8981\u751f\u6210ROC\u66f2\u7ebf\u6570\u636e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>sklearn<\/code>\u5e93\u4e2d\u7684<code>roc_curve<\/code>\u51fd\u6570\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86<code>sklearn<\/code>\u548c<code>matplotlib<\/code>\u5e93\u3002\u901a\u8fc7\u8c03\u7528<code>roc_curve<\/code>\u51fd\u6570\u5e76\u4f20\u5165\u771f\u5b9e\u6807\u7b7e\u548c\u9884\u6d4b\u6982\u7387\uff0c\u60a8\u5c06\u83b7\u5f97\u5047\u9633\u6027\u7387\u3001\u771f\u9633\u6027\u7387\u548c\u9608\u503c\u3002\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236ROC\u66f2\u7ebf\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u4e8c\u5206\u7c7b\u95ee\u9898\u7684\u6570\u636e\uff1f<\/strong><br \/>\u5904\u7406\u4e8c\u5206\u7c7b\u95ee\u9898\u7684\u6570\u636e\u901a\u5e38\u5305\u62ec\u6570\u636e\u7684\u9884\u5904\u7406\u3001\u7279\u5f81\u9009\u62e9\u548c\u6a21\u578b\u8bad\u7ec3\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u5e93\u6765\u52a0\u8f7d\u548c\u6e05\u6d17\u6570\u636e\uff0c<code>scikit-learn<\/code>\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u7528\u4e8e\u7279\u5f81\u9009\u62e9\u548c\u6784\u5efa\u5206\u7c7b\u6a21\u578b\u3002\u786e\u4fdd\u4f7f\u7528\u5408\u9002\u7684\u8bc4\u4f30\u6307\u6807\uff08\u5982\u51c6\u786e\u7387\u3001F1\u5206\u6570\u7b49\uff09\u6765\u8bc4\u4f30\u6a21\u578b\u8868\u73b0\u3002<\/p>\n<p><strong>\u5982\u4f55\u63d0\u5347ROC\u66f2\u7ebf\u4e0b\u7684\u9762\u79ef\uff08AUC\uff09\u503c\uff1f<\/strong><br \/>\u63d0\u5347AUC\u503c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u4f18\u5316\u6a21\u578b\u7684\u8d85\u53c2\u6570\u53ef\u80fd\u4f1a\u6539\u5584\u5206\u7c7b\u6548\u679c\u3002\u5176\u6b21\uff0c\u5c1d\u8bd5\u4e0d\u540c\u7684\u7279\u5f81\u7ec4\u5408\uff0c\u6216\u8005\u4f7f\u7528\u66f4\u590d\u6742\u7684\u7b97\u6cd5\uff08\u5982\u968f\u673a\u68ee\u6797\u3001XGBoost\u7b49\uff09\u4e5f\u53ef\u80fd\u63d0\u9ad8\u6027\u80fd\u3002\u6b64\u5916\uff0c\u6570\u636e\u96c6\u7684\u5e73\u8861\u6027\u4e5f\u5f88\u5173\u952e\uff0c\u60a8\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u8fc7\u91c7\u6837\u6216\u6b20\u91c7\u6837\u6280\u672f\u6765\u5904\u7406\u4e0d\u5e73\u8861\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"ROC\u4e8c\u5206\u7c7b\u66f2\u7ebf\u6570\u636e\u5728Python\u4e2d\u5982\u4f55\u6536\u96c6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528scikit-learn\u5e93\u4e2d\u7684\u51fd\u6570\u3001\u624b [&hellip;]","protected":false},"author":3,"featured_media":1138732,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1138725"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1138725"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1138725\/revisions"}],"predecessor-version":[{"id":1138733,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1138725\/revisions\/1138733"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1138732"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1138725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1138725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1138725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}