Description
Description
Type error thrown when handing over an options dictionary to gridsearchs fit method like so:
grid_search.fit(train[["A", "B"]], train["C"], **fit_options)
This worked for 0.21.3, but doesn't for 0.22.0, so this might be a regression. Behavior change was introduced here: https://github.com/scikit-learn/scikit-learn/blame/master/sklearn/model_selection/_search.py#L651
Steps/Code to Reproduce
from sklearn.linear_model import HuberRegressor
from sklearn.model_selection import GridSearchCV
import pandas as pd
train = pd.DataFrame({"A": [1, 2, 3, 5, 2], "B": [4, 5, 6, 4, 1], "C": [5, 7, 9, 9, 3]})
hyper_parameter_tune = {
"epsilon": [1, 1.5]
}
fit_options = {
"sample_weight": 1
}
gridsearch_params = {
"cv": 2
}
gsearch = GridSearchCV(param_grid=hyper_parameter_tune,
estimator=HuberRegressor(),
**gridsearch_params
)
gsearch.fit(train[["A", "B"]], train["C"], **fit_options)
observation = pd.DataFrame({"A": [5], "B": [2]})
print(gsearch.predict(observation))
Expected Results
No Error thrown: TypeError: Singleton array array(1) cannot be considered a valid collection
Actual Results
Traceback (most recent call last):
File "/home/stepo/PycharmProjects/untitled/test.py", line 24, in
gsearch.fit(train[["A", "B"]], train["C"], groups=None, **fit_options)
File "/home/stepo/PycharmProjects/untitled/venv/lib/python3.7/site-packages/sklearn/model_selection/_search.py", line 652, in fit
fit_params_values = indexable(*fit_params.values())
File "/home/stepo/PycharmProjects/untitled/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 237, in indexable
check_consistent_length(*result)
File "/home/stepo/PycharmProjects/untitled/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 208, in check_consistent_length
lengths = [_num_samples(X) for X in arrays if X is not None]
File "/home/stepo/PycharmProjects/untitled/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 208, in
lengths = [_num_samples(X) for X in arrays if X is not None]
File "/home/stepo/PycharmProjects/untitled/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 152, in _num_samples
" a valid collection." % x)
TypeError: Singleton array array(1) cannot be considered a valid collection.
Versions
System:
python: 3.7.5 (default, Nov 20 2019, 09:21:52) [GCC 9.2.1 20191008]
executable: /home/stepo/PycharmProjects/untitled/venv/bin/python
machine: Linux-5.3.0-24-generic-x86_64-with-Ubuntu-19.10-eoan
Python dependencies:
pip: 19.0.3
setuptools: 40.8.0
sklearn: 0.22
numpy: 1.17.4
scipy: 1.3.3
Cython: None
pandas: 0.25.3
matplotlib: None
joblib: 0.14.1
Built with OpenMP: True