scikit-learn / 高斯过程不是尺度不变的

scikit-learn / Gaussian Process is not scale invariant

我正在使用库 scikit-learn 测试高斯过程回归,我对它给我的置信区间不满意。 这让我意识到这些不是尺度不变的:如果函数按比例放大(在每个轴上成比例),置信区间就会变得更大。

也许图片会更好地解释它: (蓝点中的采样点,真实函数为绿色,近似值为蓝色,置信区间=均值+/- 2sd =灰色区域)

函数缩放 x 1:

函数缩放 x 100:

直觉上,这些置信区间应该是尺度不变的,对吗?我们与其他图书馆获得相同的东西吗?

提前致谢!

PS : 代码

# -*- coding: utf-8 -*-
"""
Created on Thu May 12 16:12:38 2016

@author: pierre
"""

import numpy as np
from sklearn import gaussian_process
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
pi=3.14

#Figure
fig = plt.figure()
ax = fig.add_subplot(111)

#Function definition
def f(x):
    return 3*((x-0.5)**2)*((np.cos(pi*x))**2)+0.2*np.sin(5*x)

# Coefficient of scale
nn=100 

#Real function points
x_real=np.linspace(0,nn,100)
y_real=nn*f(x_real/nn).ravel()

#Four points sampled
X = nn*np.atleast_2d([0.,.2,.5,1.]).T
y = nn*f(X/nn).ravel()

#For the approximation
x = np.atleast_2d(np.linspace(0, nn, 200)).T

#GP call
gp = gaussian_process.GaussianProcess()
gp.fit(X, y)  
y_pred, sigma2_pred = gp.predict(x, eval_MSE=True)

#Plots
ax.scatter(X,y,s=400) #Sampled points
ax.plot(x,y_pred) #Approximation
ax.fill_between(x.ravel(),y_pred-10*sigma2_pred,y_pred+10*sigma2_pred,color='black',alpha=0.1) #Confidence intervals
ax.plot(x_real,y_real) #True function

您需要取 sigma2_pred 的平方根,因为这是 MSE,或者表示 平方 误差。置信区间应基于其平方根,如下所示:

#GP call
gp = gaussian_process.GaussianProcess()
gp.fit(X, y)  
y_pred, sigma2_pred = gp.predict(x, eval_MSE=True)
sd_pred = np.sqrt(sigma2_pred)

#Plots
ax.scatter(X,y,s=400) #Sampled points
ax.plot(x,y_pred) #Approximation
ax.fill_between(x.ravel(),y_pred-10*sd_pred,y_pred+10*sd_pred,color='black',alpha=0.1) #Confidence intervals
ax.plot(x_real,y_real) #True function

有关 scikit-learn 文档页面上的示例,请参阅 here。他们也取平方根。