Scikit learn 谁能帮我学习一下sklearn.metrics.roc#u曲线';s的用途以及该函数的期望值是什么?
我试图从networkx图形的数据结构中构造2个numpy ndarray-s,这些数据结构看起来像元组列表和简单列表。我想做一个roc曲线,其中Scikit learn 谁能帮我学习一下sklearn.metrics.roc#u曲线';s的用途以及该函数的期望值是什么?,scikit-learn,Scikit Learn,我试图从networkx图形的数据结构中构造2个numpy ndarray-s,这些数据结构看起来像元组列表和简单列表。我想做一个roc曲线,其中 验证集是上面提到的G图边元组列表,我正试图这样构造: 它看起来是这样的:[(1344,1),(2,23,0),(3,5,0),…(333334,1)] 前2个数字表示2个节点,第3个数字表示它们之间是否有边。1表示边,0表示无边 然后roc_曲线期望文档中有一个叫做y_分数的东西。我有一个使用名为preferential attachment的方法制
FPRs, TPRs, thresholds = roc_curve(y_validation,
positive_class_predicted_probabilities,
pos_label=1)
它实际上只是Ctrl C+Ctrl V。但它表示值错误和“不支持多类多输出格式”。请注意,我不是一名程序员,只是一名数学分析师。下面的代码绘制了两种射频模型的ROC曲线:
from sklearn.metrics import roc_curve
#create array of probabilities
y_test_predict1_probaRF = rf1.predict_proba(X_test)
y_test_predict2_probaRF = rf2.predict_proba(X_test)
RFfpr1, RFtpr1, thresholds = roc_curve(y_test, y_test_predict1_probaRF[:,1])
RFfpr2, RFtpr2, thresholds = roc_curve(y_test, y_test_predict2_probaRF[:,1])
def plot_roc_curve (fpr, tpr, label = None):
plt.plot(fpr, tpr, linewidth = 2, label = label)
plt.plot([0,1], [0,1], "k--")
plt.axis([0,1,0,1])
plt.xlabel("False positive rate")
plt.ylabel("True positive rate")
plot_roc_curve (RFfpr1,RFtpr1,"RF1")
plot_roc_curve (RFfpr2,RFtpr2,"RF2")
plt.legend()
plt.show()
第一个参数,
y_true
,需要仅为true标签,在本例中为0/1,没有节点对。只需确保数组的索引y\u验证
和pref\u att\u类型
匹配即可
FPRs, TPRs, thresholds = roc_curve(y_validation,
positive_class_predicted_probabilities,
pos_label=1)
from sklearn.metrics import roc_curve
#create array of probabilities
y_test_predict1_probaRF = rf1.predict_proba(X_test)
y_test_predict2_probaRF = rf2.predict_proba(X_test)
RFfpr1, RFtpr1, thresholds = roc_curve(y_test, y_test_predict1_probaRF[:,1])
RFfpr2, RFtpr2, thresholds = roc_curve(y_test, y_test_predict2_probaRF[:,1])
def plot_roc_curve (fpr, tpr, label = None):
plt.plot(fpr, tpr, linewidth = 2, label = label)
plt.plot([0,1], [0,1], "k--")
plt.axis([0,1,0,1])
plt.xlabel("False positive rate")
plt.ylabel("True positive rate")
plot_roc_curve (RFfpr1,RFtpr1,"RF1")
plot_roc_curve (RFfpr2,RFtpr2,"RF2")
plt.legend()
plt.show()