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)


                                

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

                                

注意:

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;

                                  

 

 

參考:

[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 官方文檔(非常詳細)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章