1
$\begingroup$

I'm working with 10 k-fold cross validation and I'm wanting to average the metrics, but I'm not getting it with sklearn. This is the way I am doing it and the metrics are being printed by fold.

from sklearn.model_selection import KFold 
from sklearn.metrics import accuracy_score, precision_score, f1_score, recall_score
from sklearn.metrics import precision_recall_fscore_support as score


k = 10
kf = KFold(n_splits=k, random_state=None)
model = clf
 
    
for train_index , test_index in kf.split(x_train):
    x_train , x_test = X.iloc[train_index,:],X.iloc[test_index,:]
    y_train , y_test = Y[train_index] , Y[test_index]
     
    model.fit(x_train,y_train)
    pred_values = model.predict(x_test)
    
    
    precision, recall, fscore, support = score(pred_values, y_test)
    print('precision: {}'.format(precision))
    print('recall: {}'.format(recall))
    print('fscore: {}'.format(fscore))
    print('support: {}'.format(support))
$\endgroup$

1 Answer 1

0
$\begingroup$

From the info you provide, I think you can do:

You can see a related question and answer on: KFold cross validation ambiguity

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.