1
I’m practicing using Python 2, but I don’t know the reason for this error. Follow below 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 mistake:
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.
The error msg says mysterious q should be a 2D matrix, so it should be:
misterioso=[[1],[1],[1]]
, making this correction this error will no longer occur, but it is likely that another error will occur. I haven’t used scikit for a long time, but there’s something wrong with your data model, the ideal.– Sidon