交叉验证
from sklearn.model_selection import cross_val_score
clf = svm.SVC(kernel='linear',C=1)
scores = cross_val_score(clf,X,y,cv=5)
#confusion matrix
from sklearn.metrics import confusion_matrix
y_true = [2,0,2,2,0,1]
y_pred = [0,0,2,2,0,2]
confusion_matrix(y_true,y_pred)
#classification report
from sklearn.metrics import classification_report
y_true = [0,1,2,2,0]
y_pred = [0,0,2,1,0]
target_names = ['class 0','class 1','class 2']
print(classification_report(y_true,y_pred,target_names=target_names))
#ROC
import numpy as np
from sklearn.metrics import roc_curve
y = np.array([1,1,2,2])
scores = np.array([0.1,0.4,0.35,0.8])
fpr,tpr,thresholds = roc_curve(y,scores,pos_label=2)
fpr
tpr
thresholds
import numpy as np
from sklearn.metrics import roc_auc_score
y_true = np.array([0,0,1,1])
y_scores = np.array([0.1,0.4,0.35,0.8])
roc_auc_score(y_true,y_scores)
参考资料:
1、交叉验证 - Vancuicide - 博客园 (cnblogs.com)
posted on 2021-12-24 17:33 enhaofrank 阅读(42) 评论(0) 编辑 收藏 举报