Estava testando o que aprendi e tenho uma dificuldade.
Coloco: x = dados[["2. Análise"]] y = dados[["até a aprovação na Conservatória"]]
Ok
treino_x = x[:75] treino_y = y[:75] teste_x = x[75:] teste_y = y[75:] teste_y.shape
print("Treinaremos com %d elementos e testaremos com %d elementos" % (len(treino_x), len(teste_x)))
Ok
Agora, quando coloco:
from sklearn.svm import LinearSVC modelo = LinearSVC() modelo.fit(treino_x, treino_y)
Sai o erro:
ValueError Traceback (most recent call last) in 1 from sklearn.svm import LinearSVC 2 modelo = LinearSVC() ----> 3 modelo.fit(treino_x, treino_y)
~\anaconda3\lib\site-packages\sklearn\svm_classes.py in fit(self, X, y, sample_weight) 226 % self.C) 227 --> 228 X, y = self.validatedata(X, y, accept_sparse='csr', 229 dtype=np.float64, order="C", 230 accept_large_sparse=False)
~\anaconda3\lib\site-packages\sklearn\base.py in validatedata(self, X, y, reset, validate_separately, *check_params) 431 y = check_array(y, *check_y_params) 432 else: --> 433 X, y = check_X_y(X, y, **check_params) 434 out = X, y 435
~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(args, **kwargs) 61 extra_args = len(args) - len(all_args) 62 if extra_args <= 0: ---> 63 return f(args, **kwargs) 64 65 # extra_args > 0
~\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, estimator) 812 raise ValueError("y cannot be None") 813 --> 814 X = check_array(X, accept_sparse=accept_sparse, 815 accept_large_sparse=accept_large_sparse, 816 dtype=dtype, order=order, copy=copy,
~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(args, **kwargs) 61 extra_args = len(args) - len(all_args) 62 if extra_args <= 0: ---> 63 return f(args, **kwargs) 64 65 # extra_args > 0
~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator) 614 array = array.astype(dtype, casting="unsafe", copy=False) 615 else: --> 616 array = np.asarray(array, order=order, dtype=dtype) 617 except ComplexWarning as complex_warning: 618 raise ValueError("Complex data not supported\n"
~\anaconda3\lib\site-packages\numpy\core_asarray.py in asarray(a, dtype, order, like) 100 return asarraywith_like(a, dtype=dtype, order=order, like=like) 101 --> 102 return array(a, dtype, copy=False, order=order) 103 104
~\anaconda3\lib\site-packages\pandas\core\generic.py in array(self, dtype) 1897 1898 def array(self, dtype=None) -> np.ndarray: -> 1899 return np.asarray(self.values, dtype=dtype) 1900 1901 def __arraywrap__(
~\anaconda3\lib\site-packages\numpy\core_asarray.py in asarray(a, dtype, order, like) 100 return asarraywith_like(a, dtype=dtype, order=order, like=like) 101 --> 102 return array(a, dtype, copy=False, order=order) 103 104
ValueError: could not convert string to float: 'Dias até a aprovação na Conservatória'