sklearn(错误的输入形状)ValueError [英] sklearn (Bad Input Shape) ValueError

查看:99
本文介绍了sklearn(错误的输入形状)ValueError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ML和sklearn领域的新手.我尝试在具有X_train[2500,800]Y_train[2500,8]的数据集上使用GaussianNB.

I am new to the world of ML and sklearn. I tried to use GaussianNB on a dataset with X_train[2500,800], Y_train[2500,8].

from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)

在运行程序时,它显示

ValueError:输入形状错误(2500,8).

ValueError: bad input shape (2500, 8).

如何将Y_train[2500,8]转换为Y_train[2500,1]?

推荐答案

OP使用的是一个热编码器,因此fit函数不适用于数组@Ishant Mrinal建议使用

OP is using a one hot encoder so the fit function won't work with the array @Ishant Mrinal recommends this

Y_train = np.argmax(Y_train, axis=1)

这将使您可以将一种热编码传递给fit函数.

That will allow you to pass the one hot encoding into the fit function.

这篇关于sklearn(错误的输入形状)ValueError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆