1
resposta

Erro modelo.fit (treino_x, treino_y)?

Abaixo segue o código e depois o erro:

Código:

from sklearn.model_selection import train_test_split
from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score

SEED = 20

treino_x, treino_y, teste_x, teste_y = train_test_split (x, y, random_state = SEED, test_size = 0.30)
print ("Treinaremos com %d elementos e testaremos com %d elementos" % (len (treino_x), len (teste_x)))

# print (treino_x.shape)
# print (treino_y.shape)
# print (teste_x.shape)
# print (teste_y.shape)

modelo = LinearSVC(max_iter = 5000)
modelo.fit (treino_x, treino_y)
previsao = modelo.predict (teste_x)

acuracia_nova = accuracy_score (teste_y, previsao) * 100
print ("taxa de acerto é de %.2f%%" % acuracia_nova)

# não entendi do porquê que tá dando este erro

Erro:

ValueError Traceback (most recent call last) in 14 15 modelo = LinearSVC(max_iter = 5000) ---> 16 modelo.fit (treino_x, treino_y) 17 previsao = modelo.predict (teste_x) 18

~\Anaconda3\lib\site-packages\sklearn\svm\classes.py in fit(self, X, y, sample_weight) 227 X, y = check_X_y(X, y, accept_sparse='csr', 228 dtype=np.float64, order="C", --> 229 accept_large_sparse=False) 230 check_classification_targets(y) 231 self.classes_ = np.unique(y)

~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator) 722 dtype=None) 723 else: --> 724 y = column_or_1d(y, warn=True) 725 assertall_finite(y) 726 if y_numeric and y.dtype.kind == 'O':

~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in column_or_1d(y, warn) 758 return np.ravel(y) 759 --> 760 raise ValueError("bad input shape {0}".format(shape)) 761 762

ValueError: bad input shape (838, 5)

1 resposta

Olá Filipe, vc já conferiu se sua variável taget possuem só número? E se ela está no formato correto?