python - csv 文件中的 RoC 曲线

标签 python machine-learning scikit-learn roc

如何使用 scikit learn 或任何其他 python 库为 csv 文件绘制 roc 曲线,如下所示:

1, 0.202
0, 0.203
0, 0.266
1, 0.264
0, 0.261
0, 0.291
.......

最佳答案

import pandas as pd
import numpy as np
import pylab as pl
from sklearn.metrics import roc_curve, auc

df = pd.read_csv('filename.csv')

y_test = np.array(df)[:,0]
probas = np.array(df)[:,1]

# Compute ROC curve and area the curve
fpr, tpr, thresholds = roc_curve(y_test, probas)
roc_auc = auc(fpr, tpr)
print("Area under the ROC curve : %f" % roc_auc)

# Plot ROC curve
pl.clf()
pl.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc)
pl.plot([0, 1], [0, 1], 'k--')
pl.xlim([0.0, 1.0])
pl.ylim([0.0, 1.0])
pl.xlabel('False Positive Rate')
pl.ylabel('True Positive Rate')
pl.title('Receiver operating characteristic')
pl.legend(loc="lower right")
pl.show()

关于python - csv 文件中的 RoC 曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23130259/

相关文章:

r - H2O 中的自定义损失函数

用于新语言的基于 python 的朴素贝叶斯分类器

python - sklearn.tree.DecisionTreeClassifier : Get all samples that fell into leaf node

python - 如何修复 ZigZag 问题中的 'list index out of range' 错误?

python - Plotly:如何对两个不同图的类别使用相同的颜色?

Python Numpy : Operation on each sequential element without for loop?

python-2.7 - TensorFlow 程序出错

python - 如何解决: Very large size tasks in spark

python - 神经网络的多维输入

python - SKlearn Tfidfvectorizer 与 Keras : expected dense_input_1 to have shape