8000 Issue on running Bayesian Search on decision tree · Issue #978 · scikit-optimize/scikit-optimize · GitHub
[go: up one dir, main page]

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

Issue on running Bayesian Search on decision tree #978

Closed
ivanvaccarics opened this issue Dec 28, 2020 · 15 comments · Fixed by #988
Closed

Issue on running Bayesian Search on decision tree #978

ivanvaccarics opened this issue Dec 28, 2020 · 15 comments · Fixed by #988

Comments

@ivanvaccarics
Copy link

I'm trying to run the BayesSearchCV on a decision tree but i found this error.
TypeError: __init__() got an unexpected keyword argument 'iid'

My code is:

from sklearn.tree import DecisionTreeClassifier 

clf = DecisionTreeClassifier()

#hypertuning paramenters
    parameter_grid = {
    'criterion':['gini','entropy'],
    'splitter':['best','random'],
    'max_depth': [5, 8,10, 15, 25],
    'min_samples_split' : [2, 5, 10, 15,20,25],
    'min_samples_leaf' : [1, 2, 5, 10,15,20],
    'random_state' : [seed],
                    }
    
    print("TUNING ############################")
    startgrid=time.time()
    cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1)
    grid_searchdt = FixedBayesSearchCV(estimator=clf, search_spaces=parameter_grid, n_jobs=-1, cv=cv,iid=False)
    bestDT = grid_searchdt.fit(x_train, y_train)
    print(bestDT.best_params_)
    best_grid_dt = bestDT.best_estimator_
    print(best_grid_dt)
    endgrid = time.time()
    print("Grid time: "+str(endgrid-startgrid))

with a simple dataset. Could you please help me? Thanks

@sergeyf
Copy link
sergeyf commented Dec 29, 2020

The newest version of scikit-learn has deprecated the iid param. If you downgrade to 0.23.2, it should work fine.

@ivanvaccarics
Copy link
Author

Thanks, now it works.

@ReneeErnst
Copy link
ReneeErnst commented Jan 11, 2021

When do you anticipate supporting the newer version of sklearn?

@AyrtonB
Copy link
AyrtonB commented Feb 2, 2021

Monkey patch that solves this issue:

def bayes_search_CV_init(self, estimator, search_spaces, optimizer_kwargs=None,
                         n_iter=50, scoring=None, fit_params=None, n_jobs=1,
                         n_points=1, iid=True, refit=True, cv=None, verbose=0,
                         pre_dispatch='2*n_jobs', random_state=None,
                         error_score='raise', return_train_score=False):

        self.search_spaces = search_spaces
        self.n_iter = n_iter
        self.n_points = n_points
        self.random_state = random_state
        self.optimizer_kwargs = optimizer_kwargs
        self._check_search_space(self.search_spaces)
        self.fit_params = fit_params

        super(BayesSearchCV, self).__init__(
             estimator=estimator, scoring=scoring,
             n_jobs=n_jobs, refit=refit, cv=cv, verbose=verbose,
             pre_dispatch=pre_dispatch, error_score=error_score,
             return_train_score=return_train_score)
        
BayesSearchCV.__init__ = bayes_search_CV_init

@fridrichmrtn
Copy link

Hi guys,

please, is there a timeline for ironing out the incompatibility with the new scikit-learn?

Thanks,

MF

@kernc kernc closed this as completed in #988 May 4, 2021
kernc added a commit that referenced this issue May 4, 2021
* Remove BayesSearchCV(iid=) parameter deprecated in sklearn

Fixes #978

* Remove now unused weights= parameter

* Update skopt/searchcv.py

Co-authored-by: Tim Head <betatim@gmail.com>

* Fix BayesSearchCV repr/pprint; Fix changed sklearn.model_selection._validation._fit_and_score

* Update searchcv.py

Further improvements for kernc previous commits.  iid totally removed to prevent troubles with sklearn utils prettyprinting. prettyprinting looks for params when print to repl. Sklearn 0.24 has changed return value after cv, so i changed dict destructuring(a litttle bit dirty)

* Update searchcv.py

* Revert unrelated changes

* PEP8 format; add comment

* Revert reverting "unrelated changes"

This is required to pass tests/test_searchcv.py
with scikit-learn 0.24+.

* Migrate BayesSearchCV to sklearn BaseSearchCV._run_search() API

Fixes #718

* add todo item

* Add WhatsNew entry

Co-authored-by: Tim Head <betatim@gmail.com>
Co-authored-by: bole1 <bolenevod@yandex.ru>
@123nishant
Copy link

@AyrtonB , with your Patch, the code is running infinitely.

@bprasad26
Copy link

I am still having this issue.

@jwwjcw
Copy link
jwwjcw commented Jun 16, 2021

me too...

@AyrtonB
Copy link
AyrtonB commented Jun 16, 2021

It's working in most of my envs but not for the one using the latest skopt release, you may have to use an older release

@JuliusJacobitz
Copy link

It's working in most of my envs but not for the one using the latest skopt release, you may have to use an older release

+1

@rohitgarg025
Copy link

0.23.2

But how to downgrade sklearn to that version?

@plainerman
Copy link

@rohitgarg025

pip install -Iv scikit-learn==0.23.2

Maybe you have to uninstall scikit before, for me it was not needed.

@siddagra
Copy link
siddagra commented Aug 12, 2021

@rohitgarg025

pip install -Iv scikit-learn==0.23.2

Maybe you have to uninstall scikit before, for me it was not needed.

Doesn't work. Gives error:

ERROR: Could not find a version that satisfies the requirement scikit-learn==0.23.2 (from versions: 0.9, 0.10, 0.11, 0.12, 0.12.1, 0.13, 0.13.1, 0.14, 0.14.1, 0.15.0b1, 0.15.0b2, 0.15.0, 0.15.1, 0.15.2, 0.16b1, 0.16.0, 0.16.1, 0.17b1, 0.17, 0.17.1, 0.18, 0.18.1, 0.18.2, 0.19b2, 0.19.0, 0.19.1, 0.19.2, 0.20rc1, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.20.4, 0.21rc2, 0.21.1, 0.21.2, 0.21.3, 0.22rc2.post1, 0.22rc3, 0.22, 0.22.1, 0.22.2.post1, 0.23.0rc1, 0.23.0, 0.23.1, 0.23.2, 0.24.dev0, 0.24.0rc1, 0.24.0, 0.24.1, 0.24.2)
ERROR: No matching distribution found for scikit-learn==0.23.2

@plainerman
Copy link

@siddagra Seems like there might be a more fundamental problem in your case, because your error message even lists 0.23.2 as a supported version.

@nee0712
Copy link
nee0712 commented Apr 5, 2022

@rohitgarg025

pip install -Iv scikit-learn==0.23.2

Maybe you have to uninstall scikit before, for me it was not needed.

It doesn't work at all
still getting the same error message

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

Successfully merging a pull request may close this issue.

0