HimanUCC HimanUCC - 1 year ago 120
Python Question

Naive bayes scikit learn warning "DeprecationWarning: Passing 1d arrays"

I know that passing 1d array is deprecated in Naive Bayes classifier, which I do not know why. However, For some reasons, once I built my model, I want to loop through a list of items and for each item I should call the naive classifier to predict the class. So, imagine my training set is X and my target class set is Y: And then I want to call the classifier for sample xx.

X = np.array([[1,0,1,1],[1,1,1,0],[0,0,0,1],[1,0,1,0])

Y = np.array([1,1,2,2])

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


How can I fix my code so I get rid off this warning?

Answer Source

Your testing data should have the same structure as your training data, modifying your testing xx to:


will get rid of the warning.