Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

BayesSearchCV: Not possible to provide list of tuples as search space parameter #926

Open
CodingKaiser opened this issue Jul 23, 2020 · 2 comments

Comments

@CodingKaiser
Copy link

CodingKaiser commented Jul 23, 2020

I have a list of tuples that I would like to cross-validate over, e.g. [(1,), (2,), (1,2)]. Providing this as the value for a key in the search_space parameter dictionary that I pass to BayesSearchCV causes an error however when I call fit():

Traceback (most recent call last):
  File "/path/to/conda/envlib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/path/to/conda/envlib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/path/to/src/main.py", line 256, in <module>
    main()
  File "/path/to/src/main.py", line 229, in main
    opt.fit(X_train, y=y_train)
  File "/path/to/conda/envlib/python3.7/site-packages/skopt/searchcv.py", line 680, in fit
    groups=groups, n_points=n_points_adjusted
  File "/path/to/conda/envlib/python3.7/site-packages/skopt/searchcv.py", line 555, in _step
    params = [[np.array(v).item() for v in p] for p in params]
  File "/path/to/conda/envlib/python3.7/site-packages/skopt/searchcv.py", line 555, in <listcomp>
    params = [[np.array(v).item() for v in p] for p in params]
  File "/path/to/conda/envlib/python3.7/site-packages/skopt/searchcv.py", line 555, in <listcomp>
    params = [[np.array(v).item() for v in p] for p in params]
ValueError: can only convert an array of size 1 to a Python scalar

I am using the following packages:
scikit-learn 0.22.2.post1
scikit-optimize 0.7.4

This is the dictionary I'm passing to BayesSearchCV:

    params = {
        'module__param1': [(1, ), (2, ), (1, 2)],
        'module__param2': [(1, )],
    }

It is interesting to note that this problem does not occur if I use GridSearchCV instead of BayesSearchCV. I've managed to find a work-around by simply wrapping the tuples inside my own class, but it would be nice to get it to work as usual.

@ellengiacometti
Copy link

Another interesting thing is that it works with Random Forest but not with ANN

@fjatelnicki
Copy link

Hey @CodingKaiser!
Could you show how did you wrap tuples to solve this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants