Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATPE RuntimeError: The reset parameter is False but there is no n_features_in_ attribute #668

Closed
thededlier opened this issue May 19, 2020 · 14 comments · Fixed by #697
Closed

Comments

@thededlier
Copy link
Contributor

thededlier commented May 19, 2020

Version: 0.2.4
I'm trying to optimise a KNN algorithm using Adaptive TPE. Here's a snippet of the code I'm running

KNN_DEFAULT_SPACE = {
    'k': scope.int(hp.quniform('k', 1, 500, 1)),
    'min_k': scope.int(hp.quniform('min_k', 1, 50, 1))
}

def _knn_algo(params):
     # Run KNN with params and crossvalidate to return loss
     return loss

def _objective(params):
    loss = _knn_algo(params)

    return {
        'loss': loss,
        'status': STATUS_OK,
        'hyperparams': params
    }

trials = Trials()

best = fmin(
            objective,
            KNN_DEFAULT_SPACE,
            algo=atpe.suggest,
            max_evals=100,
            trials=trials,
        )

The first 10 initialization rounds run fine. However after that I run into this exception

 File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/hyperopt/fmin.py", line 482, in fmin
    show_progressbar=show_progressbar,
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/hyperopt/base.py", line 686, in fmin
    show_progressbar=show_progressbar,
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/hyperopt/fmin.py", line 509, in fmin
    rval.exhaust()
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/hyperopt/fmin.py", line 330, in exhaust
    self.run(self.max_evals - n_done, block_until_done=self.asynchronous)
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/hyperopt/fmin.py", line 266, in run
    new_ids, self.domain, trials, self.rstate.randint(2 ** 31 - 1)
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/hyperopt/atpe.py", line 1613, in suggest
    hyperparameterConfig, results, currentTrials=[]
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/hyperopt/atpe.py", line 763, in recommendNextParameters
    transformed = scalingModel.transform([[stats[feature]]])[0][0]
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/sklearn/preprocessing/_data.py", line 794, in transform
    force_all_finite='allow-nan')
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/sklearn/base.py", line 436, in _validate_data
    self._check_n_features(X, reset=reset)
  File "/home/rohan/auto-surprise-venv/lib/python3.6/site-packages/sklearn/base.py", line 373, in _check_n_features
    "The reset parameter is False but there is no "
RuntimeError: The reset parameter is False but there is no n_features_in_ attribute. Is this estimator fitted?

It seems that the issue arises when transforming the scaling model. Any ideas on the exact reason for this?

Thanks in advance

@thededlier
Copy link
Contributor Author

Workaround: I was using scikit-learn version 0.23.0. Going back to version 0.22.0 solved this for me

@rydevera3
Copy link

@thededlier - I just experienced the exact same thing. When I dove into the debug it was trying to scale a single scalar value. I wasn't able to fix it myself but that was the issue. I will try your workaround.

@Saibamen
Copy link

FYI: I had this same problem, when using latest sklearn version (https://pypi.org/project/sklearn/#history) on Azure App Service.

It works good on Kubernetes in Azure all the time.

BTW: It worked without any problems 2 months ago, even if I used sklearn package "from 2015"...

@sobia-shahid
Copy link

Workaround: I was using scikit-learn version 0.23.0. Going back to version 0.22.0 solved this for me

how we go back to old version?

@Saibamen
Copy link

scikit-learn==0.22.2.post1 in your requirements.txt file

@giridhar-pamisetty
Copy link

Yes, going back to older version has worked for me.

pip install scikit-learn==0.22.2.post1

@marctorsoc
Copy link
Member

shouldn't the PR #697 solve this issue? why would you like to go back? @sobia-shahid @giridhar-pamisetty

@diegoseguraes
Copy link

the issue seems to be scikit-learn version 23.0, going back to scikit-lear 22.2 solved the problem for me.. Used this code in Anaconda Command Prompt
pip install scikit-learn==0.22.2.post1

@fx-practic
Copy link

Had same problem. Returning to scikit-lear 22.2 solved the problem. Thank you.
@diegoseguraes thanks for the exact solution!!

@sumanth13131
Copy link

scikit-learn==0.22.2.post1 works for me

@madprogramer
Copy link

scikit-learn==0.22 seems to also work, even if it gives a warning. Thank you all for the head's up!

Does anyone know what's causing this?

@badyalgaurav
Copy link

There should be a solution with the latest build of Scikit learn.... Because sometimes peoples are working with some functions that are not available in previous, so how to synch in that case?

@amazingclaude
Copy link

I had the same issue, I was using scikit-learn== 0.23.1, I simply run the code:
scikit-learn==0.22.2.post1
and everything got solved.

@badyalgaurav
Copy link

Yeah I also had done the same thing and it works...but what we can do if some methods needs scikit-learn >0.22.2

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

Successfully merging a pull request may close this issue.