sklearn (Bad Input Shape) ValueError

放肆的年华 提交于 2019-12-20 03:48:07

问题


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)

On running the program, it is showing

ValueError: bad input shape (2500, 8).

How do i convert Y_train[2500,8] to Y_train[2500,1]?


回答1:


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)

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



来源:https://stackoverflow.com/questions/45768899/sklearn-bad-input-shape-valueerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!