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正是我们