from sklearn.model_selection import train_test_split
from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score
import numpy as np
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)
a mensagem de erro segue abaixo:
ValueError Traceback (most recent call last)
<ipython-input-22-ab9108cd6e3d> in <module>
8 np.random.seed(SEED)
9 treino_x, teste_x, treino_y, teste_y = train_test_split(x, y, test_size = 0.25,
---> 10 stratify = y)
11 print("Treinaremos com %d elementos e testaremos com %d elementos" % (len(treino_x), len(teste_x)))
12
~\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py in train_test_split(*arrays, **options)
2098 n_samples = _num_samples(arrays[0])
2099 n_train, n_test = _validate_shuffle_split(n_samples, test_size, train_size,
-> 2100 default_test_size=0.25)
2101
2102 if shuffle is False:
~\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py in _validate_shuffle_split(n_samples, test_size, train_size, default_test_size)
1780 'resulting train set will be empty. Adjust any of the '
1781 'aforementioned parameters.'.format(n_samples, test_size,
-> 1782 train_size)
1783 )
1784
ValueError: With n_samples=1, test_size=0.25 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters.