Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

[Dúvida] ValueError: Found input variables with inconsistent numbers of samples: [1, 365]

Coloquei o código = X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=2811)

Retornou= ValueError                                Traceback (most recent call last)
Cell In[72], line 1
----> 1 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=2811)

File ~\Downloads\Alura\Lib\site-packages\sklearn\utils\_param_validation.py:211, in validate_params.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    205 try:
    206     with config_context(
    207         skip_parameter_validation=(
    208             prefer_skip_nested_validation or global_skip_validation
    209         )
    210     ):
--> 211         return func(*args, **kwargs)
    212 except InvalidParameterError as e:
    213     # When the function is just a wrapper around an estimator, we allow
    214     # the function to delegate validation to the estimator, but we replace
    215     # the name of the estimator by the name of the function in the error
    216     # message to avoid confusion.
    217     msg = re.sub(
    218         r"parameter of \w+ must be",
    219         f"parameter of {func.__qualname__} must be",
    220         str(e),
    221     )

File ~\Downloads\Alura\Lib\site-packages\sklearn\model_selection\_split.py:2614, in train_test_split(test_size, train_size, random_state, shuffle, stratify, *arrays)
   2611 if n_arrays == 0:
   2612     raise ValueError("At least one array required as input")
-> 2614 arrays = indexable(*arrays)
   2616 n_samples = _num_samples(arrays[0])
   2617 n_train, n_test = _validate_shuffle_split(
   2618     n_samples, test_size, train_size, default_test_size=0.25
   2619 )

File ~\Downloads\Alura\Lib\site-packages\sklearn\utils\validation.py:455, in indexable(*iterables)
    436 """Make arrays indexable for cross-validation.
    437 
    438 Checks consistent length, passes through None, and ensures that everything
   (...)
    451     sparse matrix, or dataframe) or `None`.
    452 """
    454 result = [_make_indexable(X) for X in iterables]
--> 455 check_consistent_length(*result)
    456 return result

File ~\Downloads\Alura\Lib\site-packages\sklearn\utils\validation.py:409, in check_consistent_length(*arrays)
    407 uniques = np.unique(lengths)
    408 if len(uniques) > 1:
--> 409     raise ValueError(
    410         "Found input variables with inconsistent numbers of samples: %r"
    411         % [int(l) for l in lengths]
    412     )

ValueError: Found input variables with inconsistent numbers of samples: [1, 365]
Como posso resolver?
2 respostas

Achei o erro!

solução!

Olá Vitor, tudo bem com você?

Que bom que encontrou o erro e poderá continuar seus estudos. Conte com a Alura nesta jornada.

Abraços e bons estudos!