Error when sorting with kmn

Asked

Viewed 23 times

0

I am trying to sort using kmn, but is giving error shown after code:

Filing cabinet search_data.py

from dados import carregar_acessos  
from sklearn.naive_bayes import MultinomialNB  
import os  

pasta="c:/users/usuario/dados"  
os.chdir(pasta)  
def particionar_treino_testes(X, Y, porcentagem_testes):  
    total = len(X)  
    if total < 5:  
        raise "E preciso mais de 5 amostras para particionar"  

    num_testes = int(len(X) * porcentagem_testes)  
    num_treino = total - num_testes  

    treinoX = X[:num_treino]  
    treinoY = Y[:num_treino]  

    testeX = X[-num_testes:]  
    testeY = Y[-num_testes:]  

    return treinoX, treinoY, testeX, testeY  

X, Y = carregar_acessos()  

treino_dados, treino_marcacoes, teste_dados, teste_marcacoes = particionar_treino_testes(X, Y, 0.1)  

modelo = MultinomialNB()  

modelo.fit(treino_dados, treino_marcacoes)  

resultado = modelo.predict(teste_dados)  
diferencas = resultado - teste_marcacoes  
total_acertos = len([d for d in diferencas if d == 0])   
total_testes = len(teste_marcacoes)  
taxa_acerto = 100.0 * total_acertos / total_testes  

print(resultado)  
print(diferencas)  
print(total_testes)  
print(taxa_acerto)

Filing cabinet py.

import os  
import pandas as pd  

pasta="c:/users/usuario/dados"  
os.chdir(pasta)  

def carregar_acessos():  
    X = []  
    Y = []  
    leitor =pd.read_csv('acesso.csv', encoding='ISO-8859-1', sep=";")  

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

    return X, Y  

The mistake is:

Traceback (most recent call last):
File "C:\Users\USUARIO\workspacePython\testes\classifica_acessos.py", line 23, in <module>
  X, Y = carregar_acessos()
File "C:\Users\USUARIO\workspacePython\testes\dados.py", line 15, in carregar_acessos
  for home, como_funciona, contato, comprou in leitor:
ValueError: too many values to unpack (expected 4)
  • What is the contents of the file acesso.csv? It looks like you expect to have only 4 columns, but the file has more than 4.

  • @Anderson Carlos Woss are three variables. I have already found example with .csv. I have tried to open using the read_csv function, but it does not work in the following lines of the method.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.