在Python中,当我在早期通过简单的绘图遇到绊脚石时,我试图进入GPy库以估算高斯过程模型。
对于我的数据,我生成了一个简单的正弦波,中间增加了平方的增长率,GPy成功地估计了初始模型。
数据生成:
## Generating data for regression
# First, regular sine wave + normal noise
x = np.linspace(0,40, num=300)
noise1 = np.random.normal(0,0.3,300)
y = np.sin(x) + noise1
# Second, an upward trending starting midway, with its own noise as well
temp = x[150:]
noise2 = 0.004*temp**2 + np.random.normal(0,0.1,150)
y[150:] = y[150:] + noise2
plt.plot(x, y)
初始模型:
## Pre-processing
X = np.expand_dims(x, axis=1)
Y = np.expand_dims(y, axis=1)
## Model
kernel = GPy.kern.RBF(input_dim=1, variance=1., lengthscale=1.)
model1 = GPy.models.GPRegression(X, Y, kernel)
## Plotting
fig = model1.plot()
GPy.plotting.show(fig, filename='basic_gp_regression_notebook')
但是,此模型指定不正确,因为数据仅使用sin(X)和X ^ 2(而不仅仅是X)创建,所以我创建了下一个模型:
X_all = np.hstack((np.sin(X), np.square(X)))
model2 = GPy.models.GPRegression(X_all, Y, kernel)
fig = model2.plot()
GPy.plotting.show(fig, filename='basic_correct_gp_regression_notebook')
但是,现在,我正在绘制错误,
Invalid value of type 'builtins.str' received for the 'size' property of scatter.marker Received value: '5'
我认为这是因为绘图仅提供sin(X)和X ^ 2,所以不知道将“ X”用作x轴。
我该如何解决?