Ich fing an, maschinelles Lernen zu lernen. Also begann ich mit Naive Bayes
mein Python-SkriptValueError in sklearn.naive_bayes.GaussianNB
import numpy as np
x = np.array([[0,0],[1,1],[0,1],[1,0]])
y = np.array([0,0,1,1])
print(x)
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
x = x.reshape(1,-1)
y = y.reshape(1,-1)
clf.fit(x,y)
a = clf.predict([[1,1]])
print(a)
der Fehler ich bin ist
[[0 0]
[1 1]
[0 1]
[1 0]]
Traceback (most recent call last):
File "ex.py", line 9, in <module>
clf.fit(x,y)
File "/usr/local/lib/python2.7/dist-packages/sklearn/naive_bayes.py", line 182, in fit
X, y = check_X_y(X, y)
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 526, in check_X_y
y = column_or_1d(y, warn=True)
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 562, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (1, 4)
, was soll ich tun?
Entfernen Sie die 'x = x.reshape (1, -1)', das ist die Ursache für Ihren Fehler. x wird zu einem 1D-Array der Länge 8, das nicht zu y passt (Länge 4). – Nuageux
@Nuageux danach bekomme ich auch diesen Fehler –
Mein Fehler, Sie sollten auch entfernen: 'y = y.reshape (1, -1)'. Warum wollten Sie einen bestimmten Grund umgestalten? – Nuageux