简体   繁体   English

Python统计模块:如何从GPy中提取置信度/预测区间?

[英]Python stats module: How to extract confidence/prediction intervals from GPy?

After having looked through all the docs and examples online, I have not been able to find a way to extract information regarding the confidence or prediction intervals from GPy models. 在在线浏览了所有文档和示例之后,我无法找到一种从GPy模型中提取有关置信度或预测间隔的信息的方法。

I generate dummy data like this, 我生成这样的伪数据,

## 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)

and then estimate a basic model, 然后估算一个基本模型,

## 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)

However, nothing makes it clear how to proceed from there... Another question here tried asking the same thing, but that answer does not work any more, and seems rather unsatisfactory, for such an important element of statistical modelling. 但是,没有什么东西使如何从那里开始变得很清楚。 这里的另一个问题试图问同样的问题,但是对于如此重要​​的统计建模元素,该答案不再起作用,并且似乎还不能令人满意。

Given a model, and a set of target x values we want to generate the intervals at, you can extract the intervals using: 给定一个模型以及我们要生成间隔的一组目标x值,您可以使用以下方法提取间隔:

intervals = model.predict_quantiles( X = target_x_vals, quantiles = (2.5, 97.5) )

You can change the quantiles argument to get the appropriate width ones. 您可以更改分位数参数以获取适当的宽度。 The documentation for this function is found at: https://gpy.readthedocs.io/en/deploy/_modules/GPy/core/gp.html 可以在以下位置找到此功能的文档: https : //gpy.readthedocs.io/en/deploy/_modules/GPy/core/gp.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM