python交叉验证分类_交叉验证分类

我使用以下分类代码得到结果:folds = 5 #number of folds for the cv

#Logistic Regression--

clf = linear_model.LogisticRegression(penalty='l1')

kf = KFold

(len(clas), n_folds=folds)

fold = 1

cms = np.array([[0,0],[0,0]])

accs = []

aucs=[]

for train_index, test_index in kf:

X_train, X_test = docs[train_index], docs[test_index]

y_train, y_test = clas2[train_index], clas2[test_index]

clf.fit(X_train, y_train)

prediction = clf.predict(X_test)

acc = accuracy_score(prediction, y_test)

cm = confusion_matrix(y_test,prediction)

pred_probas = clf.predict_proba(X_test)[:,1]

fpr, tpr, thresholds = metrics.roc_curve(y_test, pred_probas)

print('Test Accuracy for fold {}: {}\n{}'.format(fold,round((acc*100),2),cm))

roc_auc = auc(fpr,tpr)

print('AUC for fold {} : {}'.format(fold,round((roc_auc*100),2)))

fold +=1

cms += cm

accs.append(acc)

aucs.append(roc_auc)

print('CV test accuracy: {}\n{}'.format(round((np.mean(accs)*100),2),cms))

print('\nCV AUC: {}'.format(round(np.mean(aucs)*100),2))

print('\nCV accuracy: %.3f +/- %.3f' % (round((np.mean(accs)*100),2),round((np.std(accs)*100),2)))

print('\nCV ROC AUC: %.3f +/- %.3f' % (round((np.mean(aucs)*100),2),round((np.std(aucs)*100),2)))

print('\nPeak accuracy: '+str(round((np.amax(accs)*100),2)))

print('\nPeak ROC AUC: '+str(round((np.amax(aucs)*100),2)))

我不确定我是不是在做一些扭扭扭的事情,但我有两个班是=406

No=139,代码给出了以下结果

^{pr2}$

一开始我只有17个没有医生,但工作很顺利。。有人能指出错误或解释发生了什么吗?在

你可能感兴趣的:(python交叉验证分类)