Problem while adding custom kernel on gaussian processes
See original GitHub issueThere’s an issue with the ability of allowing ppl to easily add custom kernels for gaussian processes.
I have custom method but keep getting error when adding it directly to the GP constructor it complains about the get_params
method.
Steps/Code to Reproduce
Example:
from sklearn.gaussian_process import GaussianProcessRegressor
X = np.random.randn(100, 4)
y = np.random.randn(100)
def custom_kernel(x=None):
x = np.random.randn(10, 3)
return x.dot(x.T)
gp = GaussianProcessRegressor(kernel=custom_kernel)
gp.fit(X, y)
Expected Results
*** TypeError: Cannot clone object 'array([0.99946371, 0.99859908, 0.99818002, 0.9994673 , 0.99954341,
0.99969851, 0.99905772, 0.99932515, 0.99906479, 0.99983097])' (type <class 'numpy.ndarray'>): it does not seem to be a scikit-learn estimator as it does not implement a 'get_params' methods.
Versions
System
python: 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 14:01:38) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
executable: /Users/jm/miniconda3/envs/tf/bin/python machine: Darwin-18.2.0-x86_64-i386-64bit
BLAS
macros: SCIPY_MKL_H=None, HAVE_CBLAS=None
lib_dirs: /Users/kirk/miniconda3/envs/tf/lib cblas_libs: mkl_rt, pthread
Python deps
pip: 18.1
setuptools: 40.5.0 sklearn: 0.20.0 numpy: 1.15.4 scipy: 1.1.0 Cython: None pandas: 0.23.4
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Custom kernel error with using fitrgp() - periodic / local ...
I am using the fitrgp() to fit a Gaussian Regression model to generated data. For this purpose, I created a dummy example, where...
Read more >Kernels in Gaussian Processes - Cross Validated
I am trying to understand intuitively how a kernel works in a Gaussian process. I know that GP are distributions over functions, in...
Read more >How to create a custom Kernel for a Gaussian Process ...
This is done for you by the Kernel class and it expects scikit-learn kernels to follow a convention, which your kernel should too:...
Read more >Kernel Cookbook
Coming up with a kernel on a new type of data used to be an easy way to get a NIPS paper. How...
Read more >Implementing a custom kernel in GPyTorch
Clearly, the kernel doesn't perform well. This is due to the lack of a lengthscale parameter, which we will add next. Adding hyperparameters¶....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
And https://scikit-learn.org/dev/modules/generated/sklearn.gaussian_process.kernels.PairwiseKernel.html#sklearn.gaussian_process.kernels.PairwiseKernel
Maybe adding an example to the user guide would be nice?
@eamanu Is there any documentation anywhere to be found on how to create a custom Kernel? Does scikit docs include this information? It’s easy to close an issue and say that’s not a Kernel. Sure. Give me an example please! If I google about how to construct custom kernel in scikit, this is the first result that comes. And all the example about constructing custom kernels are functions related to the svm api. As you @jnothman have already understood this is confusing to the end user since the interface is not consistent. And correct me if I’m wrong but still cannot find any documentation on creating custom kernels in GPs. Apparently that’s class and should implement the
get_params
method, one has to look into the actual api code to figure things out, but even then things are not completely clear. Thanks!