1

我正在尝试在集成装袋分类器/回归器中使用 GaussianProcess 分类器或回归器。高斯内核在集成工作流之外工作正常,但只要它在集成模型中实现(此处装袋),它就会生成有关其内核的错误,声明“CompoundKernel”对象没有属性“k1”。我使用以下更简单的代码重新生成了错误:

import numpy as np
import pandas as pd
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import CompoundKernel, WhiteKernel, RBF
from sklearn.ensemble import BaggingRegressor
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)
bag = BaggingRegressor(n_estimators=10, base_estimator = gaus)
bag.fit(df1, df2) # executing this line generates the error

以下是错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-32-af2dcdf3f94c> in <module>
      2 gaus = GaussianProcessRegressor(kernel = kernel)
      3 bag = BaggingRegressor(n_estimators=10, base_estimator = gaus)
----> 4 bag.fit(df1, df2)
......
......
--> 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'

请注意,将复合内核更改为单个内核(例如 RBF)可以解决问题,但我想在我的模型中使用混合内核。您对我如何处理这个问题有任何想法吗?

4

0 回答 0