AttributeError of compound kernel of Gaussian processes
See original GitHub issueDescribe the bug
I am trying to use GaussianProcess classifier or regressor using the compound kernel (comprised of RBF and white kernels). Fit method of Gaussian process generates an error regarding its kernel, declaring that ‘CompoundKernel’ object has no attribute ‘k1’. I regenerated the error using the following simpler code:
Steps/Code to Reproduce
import numpy as np
import pandas as pd
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import CompoundKernel, WhiteKernel, RBF
X1 = np.random.exponential(range(0,10), size = 10)
X2 = np.random.poisson(range(0,10), size = 10)
y = np.random.normal(size = 10)
df = pd.DataFrame()
df["X1"] = X1
df["X2"] = X2
df["y"] = y
df1 = df.iloc[:,0:2]
df2 = df.iloc[:,2]
kernel = CompoundKernel([WhiteKernel(noise_level=2), RBF(length_scale=3)])
gaus = GaussianProcessRegressor(kernel = kernel)
gaus.fit(df1, df2) # executing this line generates the error
Expected Results
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_2056/1607188154.py in <module>
15 kernel = CompoundKernel([WhiteKernel(noise_level=2), RBF(length_scale=3)])
16 gaus = GaussianProcessRegressor(kernel = kernel)
---> 17 gaus.fit(df1, df2) # executing this line generates the error
......
......
540 The non-fixed, log-transformed hyperparameters of the kernel
541 """
--> 542 k_dims = self.k1.n_dims
543 for i, kernel in enumerate(self.kernels):
544 kernel.theta = theta[i * k_dims:(i + 1) * k_dims]
AttributeError: 'CompoundKernel' object has no attribute 'k1'
Actual Results
The code works well without using the compound kernel (e.g., RBF only), and the way I built the compound kernel is exactly according to the provided format of sklearn. Not sure why I receive this attribute error.
Versions
System:
python: 3.7.12 (default, Sep 10 2021, 00:21:48) [GCC 7.5.0]
executable: /usr/bin/python3
machine: Linux-5.4.104+-x86_64-with-Ubuntu-18.04-bionic
Python dependencies:
pip: 21.1.3
setuptools: 57.4.0
sklearn: 1.0.1
numpy: 1.19.5
scipy: 1.4.1
Cython: 0.29.24
pandas: 1.1.5
matplotlib: 3.2.2
joblib: 1.1.0
threadpoolctl: 3.0.0
Built with OpenMP: True
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
scikit learn - 'CompoundKernel' object has no attribute 'k1'
'CompoundKernel' object has no attribute 'k1' - error of compound kernel in gaussian process inside ensemble learning · scikit-learn ...
Read more >sklearn.gaussian_process.GaussianProcessClassifier
Gaussian process classification (GPC) based on Laplace approximation. The implementation is based on Algorithm ... Also kernel cannot be a CompoundKernel .
Read more >Gaussian processes (3/3) - exploring kernels
A kernel (or covariance function) describes the covariance of the Gaussian process random variables. Together with the mean function the kernel completely ...
Read more >Kernel Cookbook
If you're looking for software to implement Gaussian process models, I recommend GPML ... However, if you want to construct an interesting composite...
Read more >A be cannot found parameter positional that - CSDN
"""Kernels for Gaussian process regression and classification. ... from sklearn.gaussian_process.kernels import CompoundKernel ... raise AttributeError(.
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
I was probably not clear, you should not use it even in classification. Basically, it is only used in the internal of scikit-learn:
Here we indeed have 3 kernels, because the model is trained in a 1-vs-rest manner, thus 1 estimator + 1 kernel for each. But it is transparent to the user.
take