Gaussian Processes Regression(GPR) 高斯过程回归 Matlab 实现

高斯过程回归(GPR)的matlab 实现, Matlab 为实现高斯过程回归提供了接口函数 fitrgp, 详细参考fitrgp官方文档 非常详细[4]

语法: 

gprMdl = fitrgp(tbl,ResponseVarName)

gprMdl = fitrgp(tbl,formula)

gprMdl = fitrgp(tbl,y)

gprMdl = fitrgp(X,y)

gprMdl = fitrgp(___,Name,Value)

 

Example 1 :

这个例子用到鲍鱼数据[1],[2], 来自于知识库[3]来预测鲍鱼的年龄. 下载数据保存到你当前的文件夹命名 'abalone.data'.

tbl = readtable('abalone.data','Filetype','text',...
     'ReadVariableNames',false);
tbl.Properties.VariableNames = {'Sex','Length','Diameter','Height',...
     'WWeight','SWeight','VWeight','ShWeight','NoShellRings'};
tbl(1:7,:)

gprMdl = fitrgp(tbl,'NoShellRings','KernelFunction','ardsquaredexponential',...
      'FitMethod','sr','PredictMethod','fic','Standardize',1)
  
ypred = resubPredict(gprMdl);

figure();
plot(tbl.NoShellRings,'r.');
hold on
plot(ypred,'b');
xlabel('x');
ylabel('y');
legend({'data','predictions'},'Location','Best');
axis([0 4300 0 30]);
hold off;

L = resubLoss(gprMdl)


                                Gaussian Processes Regression(GPR) 高斯过程回归 Matlab 实现_第1张图片

Example 2 :

简单的生成数据训练GRP模型并画出预测值

rng(0,'twister'); % For reproducibility
n = 1000;
x = linspace(-10,10,n)';
y = 1 + x*5e-2 + sin(x)./x + 0.2*randn(n,1);

gprMdl = fitrgp(x,y,'Basis','linear',...
      'FitMethod','exact','PredictMethod','exact');
ypred = resubPredict(gprMdl);
plot(x,y,'b.');
hold on;x
plot(x,ypred,'r','LineWidth',1.5);
xlabel('x');
ylabel('y');
legend('Data','GPR predictions');
hold off

                                Gaussian Processes Regression(GPR) 高斯过程回归 Matlab 实现_第2张图片

注意:

ypred = resubPredict(gprMdl), 注意这里的预测语句,resubPredict(gprMdl) 这个函数输入是训练好的gprMdl模型。然后对应于训练数据x预测相应的y,是用训练好的模型,重新预测训练数据x对应的y值.

 

Example 3 :

简单数据训练高斯过程回归模型并画出带有间隔(置信区间的)图形 

x = [-4;-2;-1;0;2];
y = [-2;0;1;2;-1];
gpr = fitrgp(x,y,'Sigma',0.1);
plot(x,y,'b+','DisplayName','Data');
hold on;
xtest = linspace(-5,5,1000)';
[pred,~,ci] = predict(gpr,xtest);
plot(xtest,pred,'r','DisplayName','Prediction');
hold on;
plot(xtest,ci(:,1),'c','DisplayName','Lower 95% Limit');
plot(xtest,ci(:,2),'k','DisplayName','Upper 95% Limit');
legend('show','Location','Best');
shg;

                                  Gaussian Processes Regression(GPR) 高斯过程回归 Matlab 实现_第3张图片

 

 

参考:

[1] Warwick J. N., T. L. Sellers, S. R. Talbot, A. J. Cawthorn, and W. B. Ford. "The Population Biology of Abalone (_Haliotis_ species) in Tasmania. I. Blacklip Abalone (_H. rubra_) from the North Coast and Islands of Bass Strait." Sea Fisheries Division, Technical Report No. 48 (ISSN 1034-3288), 1994.

[2] S. Waugh. "Extending and Benchmarking Cascade-Correlation", PhD Thesis. Computer Science Department, University of Tasmania, 1995.

[3] Lichman, M. UCI Machine Learning Repository, Irvine, CA: University of California, School of Information and Computer Science, 2013. http://archive.ics.uci.edu/ml.

[4] fitrgp 官方文档(非常详细)

你可能感兴趣的:(Matlab,数学概念,统计学理论,理论)