遵循pythonhosted.org的文档。
我希望仅通过高斯过程绘制没有曲线拟合的点和表示标准偏差的背景灰色。
import sys
from numpy.random import seed
from infpy.gp import GaussianProcess, gp_1D_X_range, gp_plot_samples_from
from pylab import plot, savefig, title, close, figure, xlabel, ylabel
# seed RNG to make reproducible and close all existing plot windows
seed(2)
close('all')
#
# Kernel
#
from infpy.gp import SquaredExponentialKernel as SE
kernel = SE([1])
#
# Part of X-space we will plot samples from
#
support = gp_1D_X_range(-10.0, 10.01, .125)
# Data
#
X = [[-5.], [-2.], [3.], [3.5]]
Y = [2.5, 2, -.5, 0.]
figure()
plot([x[0] for x in X], Y, 'ks')
gp = GaussianProcess(X, Y, kernel)
gp_plot_samples_from(gp, support, num_samples=0)
xlabel('x')
ylabel('f(x)')
title('Samples')
savefig('samples.png')
savefig('samples.eps')
答案 0 :(得分:0)
修改以下行:
from pylab import plot, savefig, title, close, figure, xlabel, ylabel
要:
from pylab import plot, savefig, title, close, figure, xlabel, ylabel, xlim, ylim
声明后:
plot([x[0] for x in X], Y, 'ks')
添加以下行:
xlim([-11, 11])
ylim([-2.5, 3.5])