在我的分类问题中,我想检查我的模型是否表现良好,所以我做了一个roc_auc_找到准确度的分数,得到值0.9856825361839688
我的问题
这是我的代码
x,y=make_classification(n_samples=2000,n_classes=2,weights=[1,1],random_state=24)
x_train, x_test, y_train, y_test=train_test_split(x,y,test_size=0.3,random_state=43)
from sklearn.neighbors import KNeighborsClassifier
knn_classifier=KNeighborsClassifier()
knn_classifier.fit(x_train, y_train)
ytrain_pred = knn_classifier.predict_proba(x_train)
print('train roc-auc: {}'.format(roc_auc_score(y_train, ytrain_pred[:,1])))
列车roc-auc: 0.9856825361839688
现在我做一个roc-auc图来检查最好的分数
fpr_1, tpr_1, thresholds_1=roc_curve(y_train, ytrain_pred[:,1])
fig,ax=plt.subplots(1,1,figsize=(15,7))
g=sns.lineplot(x=fpr_1,y=tpr_1,ax=ax,color='green')
g.set_xlabel('False Positive Rate')
g.set_ylabel('True Positive Rate')
g.set(xlim=(0,0.8))
从图中我可以直观地看到,从0.2(FPR)开始,TPR处于最大值,因此从roc开始_auc_我得到的分数,我是否应该认为该方法以0.2为阈值
我显式地计算了每个阈值的准确度分数。
_result=pd.concat([pd.Series(thresholds_1),pd.Series(accuracy_ls)],axis=1)
_result.columns=['threshold','accuracy score']
所以,我是不是应该认为大鹏_auc_无论阈值是多少,score都会给出最高的分数?
发布于 2021-02-25 15:59:04
方法roc_auc_score
用于对分类器进行评估。它告诉你roc曲线下的面积。(https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc\_auc\_score.html)
roc_auc_score == 1
-理想分类器。
对于具有相同数量的样本的二进制分类,评估数据集中的两个类别:roc_auc_score == 0.5
-随机分类器。
在这种方法中,我们不会相互比较阈值。
哪个阈值更好,您应该自己决定,这取决于您试图解决的业务问题。对你来说,精确度和召回率哪个更重要?
https://stackoverflow.com/questions/66360288
复制相似问题