ROC曲线绘制(Python)_python将分训练组和验证组绘制roc曲线

from sklearn.datasets import make_blobs
from sklearn. model_selection import train_test_split
import matplotlib.pyplot as plt
%matplotlib inline


然后使用下面make\_blobs函数,生成一个二分类的数据不平衡数据集;


使用train\_test\_split函数划分训练集和测试集数据;


训练SVC模型。



X,y = make_blobs(n_samples=(4000,500), cluster_std=[7,2], random_state=0)

X_train,X_test,y_train, y_test = train_test_split(X,y,random_state=0)

clf = SVC(gamma=0.05).fit(X_train, y_train)


![](https://img-blog.csdnimg.cn/img_convert/64e560eb79692da614df3b42ff3f238a.jpg)



fpr,tpr, thresholds = roc_curve(y_test,clf.decision_function(X_test))

plt.plot(fpr,tpr,label=‘ROC’)

plt.xlabel(‘FPR’)
plt.ylabel(‘TPR’)


从上面的代码可以看到,我们使用roc\_curve函数生成三个变量,分别是fpr,tpr, thresholds,也就是假正例率(FPR)、真正例率(TPR)和阈值。


而其中的fpr,tpr正是我们
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值