using confusion matrix as scoring metric in cross validation in scikit learn

前端 未结 5 605
野性不改
野性不改 2021-01-31 11:15

I am creating a pipeline in scikit learn,

pipeline = Pipeline([
    (\'bow\', CountVectorizer()),  
    (\'classifier\', BernoulliNB()), 
])

a

5条回答
  •  梦毁少年i
    2021-01-31 12:01

    You could use cross_val_predict(See the scikit-learn docs) instead of cross_val_score.

    instead of doing :

    from sklearn.model_selection import cross_val_score
    scores = cross_val_score(clf, x, y, cv=10)
    

    you can do :

    from sklearn.model_selection import cross_val_predict
    from sklearn.metrics import confusion_matrix
    y_pred = cross_val_predict(clf, x, y, cv=10)
    conf_mat = confusion_matrix(y, y_pred)
    

提交回复
热议问题