python - 错误 : "Number of classes in y_true not equal to the number of columns in ' y_score'"

标签 python roc multiclass-classification imbalanced-data

我有一个不平衡的多类数据集,当我尝试计算 roc_auc_score 时出现此错误:ValueError:y_true 中的类数不等于“y_score”中的列数。

代码如下:

model = svm.SVC(kernel='linear', probability=True)
model.fit(X_train, y_train)
y_prob = model.predict_proba(X_test)
macro_roc_auc_ovr = roc_auc_score(y_test, y_prob, multi_class="ovr",
                              average="macro")

解决这个问题的任何建议。

谢谢

最佳答案

当我在每个折叠中没有至少一个类的例子时,我就遇到了这个问题。为了解决这个问题,我将 KFold 替换为 StratifiedKFold。

我觉得可能是你的split方法有问题。您也可以要求对拆分进行分层,并将 stratify=y 传递给 train_test_split 方法(如果您使用的是这种方法)

关于python - 错误 : "Number of classes in y_true not equal to the number of columns in ' y_score'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65325292/

相关文章:

machine-learning - 如何计算投票集成分类器的AUC(曲线下面积)?

r - R中的3类AUC计算(pROC包)

machine-learning - 选择哪个分类?

python - 第 10 亿次相对进口

r - R 中的支持向量机 : "Predictor must be numeric or ordered."

python - scikit-learn 在多类分类中默认使用 One-Vs-Rest 吗?

python - 应用 PyTorch CrossEntropy 方法进行多类分割

python - django安装问题[python]

Python:os.read() 在 fd 上阻塞

Python 组合导致 AttributeError