python - 重塑 np.array 以防止错误:searn GPR XA 和 XB 必须具有相同的列数
问题描述
我想使用 scikit-learn 的高斯过程回归器。我用于预测和函数的数据,执行 gpr,如下所示:
训练数据:
X[[ 43.3301 -196.211 1157.89 2.71431 -191.664 1159.45
-28.9847 -191.544 1158.88 5.99311 -218.226 1229.12
38.9442 -214.853 1256.5 ]
[ 43.3212 -196.12 1157.79 2.7885 -191.587 1159.45
-29.0067 -191.53 1158.88 5.94141 -218.028 1229.11
38.8952 -214.711 1256.48]...] <class 'numpy.ndarray'> (14, 15)
目标数据:
y[[ 9.14779 -186.67 1294.53]
[ 9.12453 -186.559 1294.33 ]
[ 8.50554 -186.254 1293.22]...] <class 'numpy.ndarray'> (14, 3)
和测试数据
x[[ -90.23126221 -245.3088 675.835]
[ -63.30067444 -256.1264 752.844]
[ -28.84734154 -236.4492 642.7713]...] <class 'numpy.ndarray'> (14, 3)
def doGPR(self, inputData, targetData, testData):
kernel = ConstantKernel(1.0, (1e-3,1e3)) * RBF(10.0, (1e-2,1e2)) + WhiteKernel(0.1, (1e-10, 0.5))
gpr = GaussianProcessRegressor(kernel= kernel, n_restarts_optimizer= 0, normalize_y= True)
gpr.fit(X, y)
predictedData, sigma = gpr.predict(x, return_std=True)
在预测阶段,我收到以下错误:
Traceback (most recent call last):
File "sklearn/gaussian_process/gpr.py", line 315, in predict
K_trans = self.kernel_(X, self.X_train_)
File "sklearn/gaussian_process/kernels.py", line 683, in __call__
return self.k1(X, Y) + self.k2(X, Y)
File "sklearn/gaussian_process/kernels.py", line 758, in __call__
return self.k1(X, Y) * self.k2(X, Y)
File "sklearn/gaussian_process/kernels.py", line 1215, in __call__
metric='sqeuclidean')
File "/usr/lib/python3/dist-packages/scipy/spatial/distance.py", line 2031, in cdist raise ValueError('XA and XB must have the same number of columns '
ValueError: XA and XB must have the same number of columns (i.e. feature dimension.)
这是否意味着我也应该将我的训练数据带入 shape (x, 3) ?我怎么能用这个嵌套数组做到这一点?
谢谢!
解决方案
推荐阅读
- postgresql - 由于 IOException,Docker 中的 Keycloak 无法启动
- flash - 为什么在开发环境之外运行我的应用程序的性能要低得多?
- html - 不知道IMG在哪里
- gnu-make - Makefiles:它们如何确定构建目标?
- c# - 在多目标项目中,我只有更严格的框架的资源可用?
- excel - 使范围内的所有单元格值为负
- python - 为外键字段创建 post_save 信号
- javascript - 初始化类型后无法再打开页面
- sql - oracle12 sdo_nn 返回最短距离对象失败
- javascript - 为什么 JavaScript 中的 return 语句不返回任何内容?