gpt4 book ai didi

python - 在 scikit learn 的交叉验证中使用混淆矩阵作为评分指标

转载 作者:太空狗 更新时间:2023-10-29 17:35:52 26 4
gpt4 key购买 nike

我正在 scikit learn 中创建一个管道,

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

并使用交叉验证计算准确度

scores = cross_val_score(pipeline,  # steps to convert raw messages      into models
train_set, # training data
label_train, # training labels
cv=5, # split data randomly into 10 parts: 9 for training, 1 for scoring
scoring='accuracy', # which scoring metric?
n_jobs=-1, # -1 = use all cores = faster
)

如何报告混淆矩阵而不是“准确度”?

最佳答案

您可以使用 cross_val_predict( See the scikit-learn docs ) 而不是 cross_val_score

而不是做:

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

你可以这样做:

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)

关于python - 在 scikit learn 的交叉验证中使用混淆矩阵作为评分指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40057049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com