import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score
x = dados[["preco", "idade_do_modelo","km_por_ano"]]
y = dados["vendido"]
SEED = 5
np.random.seed(SEED)
treino_x, teste_x, treino_y, teste_y = train_test_split(x, y, test_size = 0.25,
stratify = y)
print("Treinaremos com %d elementos e testaremos com %d elementos" % (len(treino_x), len(teste_x)))
modelo = LinearSVC()
modelo.fit(treino_x, treino_y)
previsoes = modelo.predict(teste_x)
acuracia = accuracy_score(teste_y, previsoes) * 100
print("A acurácia foi %.2f%%" % acuracia)
KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2896 try: -> 2897 return self.engine.getloc(key) 2898 except KeyError:
pandas/libs/index.pyx in pandas.libs.index.IndexEngine.get_loc()
pandas/libs/index.pyx in pandas.libs.index.IndexEngine.get_loc()
pandas/libs/hashtableclass_helper.pxi in pandas.libs.hashtable.PyObjectHashTable.getitem()
pandas/libs/hashtableclass_helper.pxi in pandas.libs.hashtable.PyObjectHashTable.getitem()
KeyError: 'vendido'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
2 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2897 return self.engine.getloc(key) 2898 except KeyError: -> 2899 return self.engine.getloc(self.maybecast_indexer(key)) 2900 indexer = self.get_indexer([key], method=method, tolerance=tolerance) 2901 if indexer.ndim > 1 or indexer.size > 1:
pandas/libs/index.pyx in pandas.libs.index.IndexEngine.get_loc()
pandas/libs/index.pyx in pandas.libs.index.IndexEngine.get_loc()
pandas/libs/hashtableclass_helper.pxi in pandas.libs.hashtable.PyObjectHashTable.getitem()
pandas/libs/hashtableclass_helper.pxi in pandas.libs.hashtable.PyObjectHashTable.getitem()
KeyError: 'vendido'