gpt4 book ai didi

python - 值错误 : multiclass-multioutput format is not supported using sklearn roc_auc_score function

转载 作者:太空宇宙 更新时间:2023-11-03 15:44:53 68 4
gpt4 key购买 nike

我正在使用 逻辑回归 进行预测。我的预测是 01。在根据给定数据训练我的模型后,以及在训练重要特征时,即 X_important_train 请参见屏幕截图。我得到大约 70% 的分数,但是当我使用 roc_auc_score(X,y)roc_auc_score(X_important_train, y_train) 时,我得到值错误: ValueError:不支持多类多输出格式

代码:

# Load libraries
from sklearn.linear_model import LogisticRegression
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import roc_auc_score

# Standarize features
scaler = StandardScaler()
X_std = scaler.fit_transform(X)

# Train the model using the training sets and check score
model.fit(X, y)
model.score(X, y)

model.fit(X_important_train, y_train)
model.score(X_important_train, y_train)

roc_auc_score(X_important_train, y_train)

截图:

enter image description here

最佳答案

首先,roc_auc_score 函数需要具有相同形状的输入参数。

sklearn.metrics.roc_auc_score(y_true, y_score, average=’macro’, sample_weight=None)

Note: this implementation is restricted to the binary classification task or multilabel classification task in label indicator format.

y_true : array, shape = [n_samples] or [n_samples, n_classes]
True binary labels in binary label indicators.

y_score : array, shape = [n_samples] or [n_samples, n_classes]
Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by “decision_function” on some classifiers).

现在,输入的是真实分数和预测分数,而不是您在发布的示例中使用的训练和标签数据。更详细,

model.fit(X_important_train, y_train)
model.score(X_important_train, y_train)
# this is wrong here
roc_auc_score(X_important_train, y_train)

你应该这样:

y_pred = model.predict(X_test_data)
roc_auc_score(y_true, y_pred)

关于python - 值错误 : multiclass-multioutput format is not supported using sklearn roc_auc_score function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50567008/

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