5

I was trying to kaggle kernel of Bayesian Hyperparam Optimization of RF. And I couldn't import sklearn.gaussian_process.GaussianProcess. Please help this poor scikit-learn newbie.

from sklearn.gaussian_process import GaussianProcess as GP

error:

Traceback (most recent call last):
  File "C:/Users/Develop/PycharmProjects/reinforcement recommandation system/BNP/bayesianoptimization-of-random-forest.py", line 24, in <module>
    from sklearn.gaussian_process import GaussianProcess as GP
ImportError: cannot import name 'GaussianProcess' from 'sklearn.gaussian_process' (C:\Users\Develop\PycharmProjects\reinforcement recommandation system\lib\site-packages\sklearn\gaussian_process\__init__.py)

Process finished with exit code 1
이희웅
  • 55
  • 1
  • 5
  • The code you link to is 4 years old, when probably the scikit-learn API was different in this case; see answer below – desertnaut Sep 03 '19 at 13:19
  • For those following the relatively old book (but still one of the best introductions on the topic imho) *Python Data Science Handbook* and reaching this error, see [this code](https://github.com/jakevdp/PythonDataScienceHandbook/issues/165) for the current version of the module (using `GaussianProcessRegressor`). – mins Jan 04 '21 at 12:55

2 Answers2

5

Depending on whether you need the regressor or classifier:

from sklearn.gaussian_process import GaussianProcessRegressor as GP

from sklearn.gaussian_process import GaussianProcessClassifier as GP

Also, have a look at the different modules

manish Prasad
  • 636
  • 6
  • 16
Ferran
  • 840
  • 9
  • 18
  • 1
    thanks, but.. I wanted to know how to use this like this: gp = GP(theta0=numpy.random.uniform(0.001, 0.05, self.dim), random_start=25). GaussianProcessRegressor and GaussianProcessClassifier don't have argument like 'theta0' :( – 이희웅 Sep 03 '19 at 15:24
  • 이희웅 I understand but please open another question or update your current one if your doubt is about how to use `GaussianProcessRegressor` or `GaussianProcessClassifier`. Regarding your comment, the functions can take the hyperparameter theta as parameter in _optimizer_. Have a look at https://scikit-learn.org/stable/modules/generated/sklearn.gaussian_process.GaussianProcessClassifier.html in the _optimizer_ paramter – Ferran Sep 04 '19 at 10:40
0

It seems that you have to use the old scikit-learn version 0.15-git

The documentation for sklearn.gaussian_process.GaussianProcess is located here: https://scikit-learn.org/0.15/modules/generated/sklearn.gaussian_process.GaussianProcess.html

I just had the same problem, but I will move on to try to understand if sklearn.gaussian_process.GaussianProcessRegressor in the current version scikit-learn 1.0.2 will work for my purposes.

thenarfer
  • 405
  • 2
  • 14