question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem while adding custom kernel on gaussian processes

See original GitHub issue

There’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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kirk86commented, Nov 12, 2018

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found