gpt4 book ai didi

scikit-learn - 获取每个交叉验证折叠的混淆矩阵

转载 作者:行者123 更新时间:2023-12-04 03:00:36 24 4
gpt4 key购买 nike

我正在使用 scikit-learn 通过交叉验证运行逻辑回归管道。我在下面的代码中从每个折叠中获得分数。我如何获得混淆矩阵?

clf = make_pipeline(MinMaxScaler(), LogisticRegression())
scores = cross_val_score(clf, X_train, y_train, cv=3)

最佳答案

我想你想要的是:

clf = make_pipeline(MinMaxScaler(), LogisticRegression())

from sklearn.model_selection import cross_val_predict
from sklearn.metrics import confusion_matrix
y_pred = cross_val_predict(clf, X_train, y_train, cv=3)
conf_mat = confusion_matrix(y, y_pred)
来自 3.1.1.2 scikit-learn 的在线文档:

The function cross_val_predict has a similar interface tocross_val_score, but returns, for each element in the input, theprediction that was obtained for that element when it was in the testset. Only cross-validation strategies that assign all elements to atest set exactly once can be used (otherwise, an exception is raised).

Note that the result of this computation may be slightly different from those obtained using cross_val_score as the elements are grouped in different ways.

关于scikit-learn - 获取每个交叉验证折叠的混淆矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49587820/

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