I'm practicing using Python 2, but I do not know the reason for this error. Below is my code with the error. And numpy and scipy are installed, because when I give the import no more error appears.
vaca1= [1,1,0]
vaca2= [1,1,0]
vaca3= [1,1,0]
cavalo4= [1,1,1]
cavalo5= [0,1,1]
cavalo6= [0,1,1]
dados=[vaca1,vaca2,vaca3,cavalo4,cavalo5,cavalo6]
marcacoes= [1, 1, 1, -1, -1, -1]
misterioso= [1, 1, 1]
...
from sklearn.naive_bayes import MultinomialNB
modelo= MultinomialNB()
modelo.fit(dados, marcacoes)
MultinomialNB(alpha=1.0, class_prior=None, fit_prior=True)
print(modelo.predict(misterioso))
Here is the error:
Traceback (most recent call last): File "", line 1, in File "C: \ tools \ Anaconda2 \ lib \ site-packages \ sklearn \ naive_bayes.py", line 66, in predict jll = self._joint_log_likelihood (X) File "C: \ tools \ Anaconda2 \ lib \ site-packages \ sklearn \ naive_bayes.py", line 724, in _joint_log_likelihood X = check_array (X, accept_sparse = 'csr') File "C: \ tools \ Anaconda2 \ lib \ site-packages \ sklearn \ utils \ validation.py", line 410, in check_array "if it contains a single sample." format (array)) ValueError: Expected 2D array, got 1D array instead: array = [1 1 1]. Reshape your data either using array.reshape (-1, 1) if your data has a single feature or array.reshape (1, -1) if it contains a single sample.