I recently started learning a bit about Machine Learning and sorting, through a course at Alura. Well, I tried to perform the first exercise, but I could not because of a mistake I can not tell what it is. Here is the code I have and the Error displayed.
Note: I tried to run the code again and now it does not recognize the SKLEARN package that I tried to import into the python file.
from sklearn.naive_bayes import MultinomialNB
pig1 = [1, 1, 0]
pig2 = [1, 1, 0]
pig3 = [1, 1, 0]
dog1 = [1, 1, 1]
dog2 = [0, 1, 1]
dog3 = [1, 0, 1]
dados = [pig1, pig2, pig3, dog1, dog2, dog3]
marcacoes = [1, 1, 1, -1, -1, -1]
misterioso = [1, 1, 1]
modelo = MultinomialNB()
modelo.fit(dados, marcacoes)
print (modelo.predict(misterioso))
And here's what the terminal returned:
Traceback (most recent call last):
File "classificacao.py", line 19, in <module>
print (modelo.predict(misterioso))
File "/Users/josecarlosferreira/machinelearning/lib/python3.6/site-packages/sklearn/naive_bayes.py", line 66, in predict
jll = self._joint_log_likelihood(X)
File "/Users/josecarlosferreira/machinelearning/lib/python3.6/site-packages/sklearn/naive_bayes.py", line 724, in _joint_log_likelihood
X = check_array(X, accept_sparse='csr')
File "/Users/josecarlosferreira/machinelearning/lib/python3.6/site-packages/sklearn/utils/validation.py", line 441, 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.
I've been trying to solve this problem for almost 4 days and can not do anything about it. If anyone can help me to get on with my studies.