python-3.x - 轴错误 : axis 1 is out of bounds for array of dimension 1 when calculating AUC

标签 python-3.x scikit-learn multiclass-classification

我有一个分类问题,我有一个 8x8 图像的像素值和图像代表的数字,我的任务是使用 RandomForestClassifier 根据像素值预测数字('Number' 属性)。数值的值可以是0-9。

from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score

forest_model = RandomForestClassifier(n_estimators=100, random_state=42)
forest_model.fit(train_df[input_var], train_df[target])
test_df['forest_pred'] = forest_model.predict_proba(test_df[input_var])[:,1]
roc_auc_score(test_df['Number'], test_df['forest_pred'], average = 'macro', multi_class="ovr")

这里它抛出一个AxisError。

回溯(最近一次调用最后一次):
文件“dap_hazi_4.py”,第 44 行,在
roc_auc_score(test_df['Number'],test_df['forest_pred'],average = 'macro', multi_class="ovo")
文件“/home/balint/.local/lib/python3.6/site-packages/sklearn/metrics/_ranking.py”,第 383 行,在 roc_auc_score
多类、平均值、样本权重)
文件“/home/balint/.local/lib/python3.6/site-packages/sklearn/metrics/_ranking.py”,第440行,_multiclass_roc_auc_score
如果不是 np.allclose(1, y_score.sum(axis=1)):
文件“/home/balint/.local/lib/python3.6/site-packages/numpy/core/_methods.py”,第 38 行,在 _sum
返回 umr_sum(a,axis, dtype, out, keepdims, initial, where)

AxisError:轴 1 超出维度 1 数组的范围

最佳答案

你确定这个[:,1]test_df['forest_pred'] = forest_model.predict_proba(test_df[input_var])[:,1]是对的?它可能是一维数组

关于python-3.x - 轴错误 : axis 1 is out of bounds for array of dimension 1 when calculating AUC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61288972/

相关文章:

machine-learning - xgboost 多类工作中 base_score 的用途是什么?

scikit-learn - 指定质心的 kmeans 聚类变换方法

svm - scikit学习svc coef0参数范围

tensorflow - 使用稀疏_分类_交叉熵时如何定义自定义标签值?

python-3.x - python multiprocessing.Queue 没有处理所有的值

python - sklearn 已安装,但 'sklearn' 不是我的 "sklearn.py"文件中的包

keras - 如何在训练期间的每个时期后计算多类分类问题的精度和召回率?

Python多处理: not using separate memory space?

python-3.x - 从 beautifulsoup4 网络抓取结果中删除特定的 <h2 类>

Python MVC 风格的 GUI 温度转换器