Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

cade a ajuda?

eu estou no python 3 e ele esta dando erro

from sklearn.naive_bayes import MultinomialNB from dados import ler_dados

X, Y = ler_dados() td = X[:90] tm = Y[:90] tsd = X[-9:] tsm = Y[-9:] IA = MultinomialNB()

IA.fit(td,tm)

linha 19: previsao = IA.predict(tsd)

dif = [previsao - tsm] diferencas = list(dif) filtrado = filter(lambda numero: numero == 0, diferencas)

valores_filtrados = list(filtrado)

print(valores_filtrados) esse aqui permite a leitura dos dados

import csv

def ler_dados(): X = [] Y = []

esse aqui permite a leitura dos dados

import csv

def ler_dados(): X = [] Y = []

arquivo = open('acesso.csv','r')
leitor = csv.reader(arquivo)

next(leitor)

for home, como_funciona, contato, comprou in leitor:
    X.append([int(home), int(como_funciona), int(contato)])
    Y.append([int(comprou)])

return X, Y

esse aqui são os dados

home,como_funciona,contato,comprou 1,1,0,0 1,1,0,0 1,1,0,0 1,1,0,0 1,1,0,0 1,0,1,1 1,1,0,0 1,0,1,1 1,1,0,0 1,0,1,1 1,1,0,1 1,0,1,1 0,0,1,0 0,0,1,0 0,0,1,0 0,0,1,0 0,0,1,0 0,1,0,0 0,0,1,0 0,1,0,0 0,0,1,0 0,1,0,0 0,0,1,0 0,1,0,0 1,0,1,1 1,1,1,1 1,1,1,1 1,0,1,1 0,1,0,0 0,0,1,0 0,1,0,0 1,0,1,1 0,0,1,0 1,0,1,1 1,0,1,1 1,0,1,1 1,0,1,1 0,0,1,0 1,1,0,0 1,0,1,1 0,1,0,0 0,0,1,0 0,1,0,0 1,0,1,1 0,0,1,0 0,0,1,0 1,0,1,1 1,0,1,1 1,1,0,0 1,1,0,0 1,1,0,0 1,1,0,0 1,0,1,1 1,1,0,0 1,0,1,1 1,1,0,0 1,0,1,1 1,1,0,0 1,0,1,1 0,0,1,0 1,0,1,1 0,1,0,0 0,0,1,0 0,1,0,0 1,0,1,1 0,1,1,1 0,0,1,0 1,0,1,1 1,0,1,1 1,1,0,0 1,1,0,0 0,0,1,0 0,0,1,0 0,0,1,0 0,0,1,0 0,1,0,0 0,0,1,0 0,1,0,0 0,0,1,0 1,1,0,1 0,0,1,0 0,0,1,0 0,0,1,0 1,0,1,1 1,0,1,1 1,1,0,0 1,1,0,0 0,0,1,0 0,0,1,0 1,0,1,1 1,0,1,1 1,1,0,0 1,1,0,0 0,0,1,0 0,0,1,0 1,1,1,1 0,0,1,0 0,1,0,0 0,0,0,0 eis o erro

C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\validation.py:752: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  y = column_or_1d(y, warn=True)
Traceback (most recent call last):
  File "C:/Users/User/Documents/guto/programas/usuario.py", line 19, in <module>
    valores_filtrados = list(filtrado)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Process finished with exit code 1
1 resposta
solução!

Opa Daniel, tudo bem?

Esse erro está acontecendo pois você está adicionando listas dentro do valor da variável Y. Ou seja, temos, nesse caso, uma lista de listas, mas o que queremos é apenas o valor acessou/não acessou. Não precisamos de uma lista nesse caso. Ou seja, basta remover os colchetes que o código deve funcionar:

Y.append(int(comprou))