www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TrainGPRModelandPlotPredictionsExample.m
%% Train GPR Model and Plot Predictions %% % Generate sample data. 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); %% % Fit a GPR model using a linear basis function and the exact fitting method % to estimate the parameters. Also use the exact prediction method. gprMdl = fitrgp(x,y,'Basis','linear',... 'FitMethod','exact','PredictMethod','exact'); %% % Predict the response corresponding to the rows of |x| (resubstitution % predictions) using the trained model. ypred = resubPredict(gprMdl); %% % Plot the true response with the predicted values. plot(x,y,'b.'); hold on; plot(x,ypred,'r','LineWidth',1.5); xlabel('x'); ylabel('y'); legend('Data','GPR predictions'); hold off