
大家好,又见面了,我是你们的朋友全栈君。
上图:

【注意!!!!! 以下代码用到的roc_curve函数(只能用于二分类),如果多分类会报错,不适用于多分类!!!!!】
附上代码:一个函数,传入三个参数
.....传入参数,训练模型,然后:
fit = model.fit(x_train, y_training)
# ROC
y_score = model.fit(x_train, y_training).predict_proba(x_test) # 随机森林
fpr, tpr, thresholds = roc_curve(y_test, y_score[:, 1])
roc_auc = auc(fpr, tpr)def drawRoc(roc_auc,fpr,tpr):
plt.subplots(figsize=(7, 5.5))
plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC Curve')
plt.legend(loc="lower right")
plt.show()drawRoc(roc, fpr, tpr)注:导入的包没有贴上,需要自己导入,复制代码即可运行发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/145587.html原文链接:https://javaforall.cn