我正在使用具有 4 个输入和一个输出的高斯过程回归。目标是通过对拟合模型执行贝叶斯优化来找到最优 X。
我用以下方式拟合模型:
kernel = C(1.0, (1e-4, 1e4))*RBF(1.0,(1e-3,1e3))
model = GaussianProcessRegressor(kernel = kernel, n_restarts_optimizer = 10,optimizer='fmin_l_bfgs_b')
model.fit(X,Y)
到目前为止,这就是我用来执行优化的方法:
bayesian_optimization = gp_minimize(lambda x: -model.predict(np.array([x])[0]),
[(0.0, 7.0), (0.0, 7.0),(0.0, 7.0),(0.0, 7.0)],
acq_func="EI",
n_calls=15,
n_random_starts=5,
random_state=1234)
我不断收到以下错误:
ValueError: Expected 2D array, got 1D array instead:
array=[3.48364567 5.72486909 4.28478326 5.39951943].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
不确定是否有可能解决问题,我已经尝试过:
bayesian_optimization = gp_minimize(lambda x: -model.predict(np.array([x]).reshape(1,-1)[0]),
[(0.0, 7.0), (0.0, 7.0),(0.0, 7.0),(0.0, 7.0)],
acq_func="EI",
n_calls=15,
n_random_starts=5,
random_state=1234)
和
bayesian_optimization = gp_minimize(lambda x: -model.predict(np.array([x]).reshape(-1, 1)[0]),
[(0.0, 7.0), (0.0, 7.0),(0.0, 7.0),(0.0, 7.0)],
acq_func="EI",
n_calls=15,
n_random_starts=5,
random_state=1234)
但没有成功。有关如何克服此类问题的任何想法?