如何让GPR提供更好的预测?

时间:2016-12-13 16:10:23

标签: python scikit-learn

我试图将GPR与其他一些形式的回归进行比较。我从线性函数中生成了一些噪声数据,但GPR返回一条相对平坦的线。

这是我的代码:

import seaborn as sns
import numpy as np
import maptlotlib.pyplot as plt
import pandas as pd

fig, ax = plt.subplots(nrows = 2, ncols = 2)
plt.subplots_adjust(wspace = 1/2, hspace = 1/2)

ax= ax.ravel()
x = np.linspace(0,10,21)

y = 2.2*x-3.5

y_noisey = y + np.random.normal(0,2,np.shape(x))

YN = pd.Series(y_noisey, index = x)
Y = pd.Series(y,index = x)


lm = LinearRegression()

ylm = lm.fit(x.reshape(-1,1),y_noisey.reshape(-1,1)).predict(x.reshape(-1,1)).ravel()

YLM = pd.Series(ylm, index = x)

gpr = GaussianProcessRegressor(kernel= Matern() + WhiteKernel(noise_level=0.2) )

ygpr = gpr.fit(x.reshape(-1,1), y_noisey.reshape(-1,1)).predict(x.reshape(-1,1)).ravel()

YGPR = pd.Series(ygpr, index = x)





YN.plot(ax = ax[0], marker = 'o', linestyle = '', label = 'Observations', clip_on = False)
Y.plot(ax =ax[0], alpha = 0.5, color = 'b', linestyle= '--' )
ax[0].set_title('True Process')

YN.rolling(3).mean().plot(ax = ax[1], color = 'g' ,label= '3 Obs Rolling Mean')
Y.plot(ax =ax[1], alpha = 0.5, color = 'b', linestyle= '--' )

YLM.plot(ax = ax[2], label = 'BLUE', color = 'r')
Y.plot(ax =ax[2], alpha = 0.5, color = 'b', linestyle= '--' )

YGPR.plot(ax = ax[3], label = 'GPR', color = 'orange')
Y.plot(ax =ax[3], alpha = 0.5, color = 'b', linestyle= '--' )


for AX in ax:

    sns.despine(ax = AX)

GPR(橙色)给出了可怕的结果。这可能是因为由于Whitekernel的使用,它明确地将信号建模为噪声。对我做错了什么的想法?

enter image description here

0 个答案:

没有答案