How can I test different kernels on my data using Gaussian process regression (GPR) ?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
%%Model_1 with default kernel
x = PPR(:,1);
y = PPR(:,2);
%%Gaussian Process Regression
gprMdl1 = fitrgp(x,y);
%%Confidence Interval
[ypred,~,yint] = predict(gprMdl1,x);
figure(1)
plot(x,y,'b.');
hold on;
plot(x,ypred1,'r','LineWidth',0.5);
xlabel('Stress');
ylabel('PRR(S-1)');
legend('Data','GPR predictions');
hold on
patch([x;flipud(x)],[yint(:,1);flipud(yint(:,2))],'k','FaceAlpha',0.1); % Prediction intervals
legend('Observed Data','GPR predictions', '95% Confidence Interval');
gprMdl.KernelInformation.KernelParameters
%%Model_2 with different kernel
x = PPR(:,1);
y = PPR(:,2);
%%Gaussian Process Regression
gprMdl2 = fitrgp(x,y, 'basis', 'linear','KernelFunction','ardsquaredexponential');
%%Confidence Interval
[ypred1,~,yint1] = predict(gprMdl2,x);
figure(2)
plot(x,y,'b.');
hold on;
plot(x,ypred1,'r','LineWidth',0.5);
xlabel('Stress');
ylabel('PRR(S-1)');
legend('Data','GPR predictions');
hold on
patch([x;flipud(x)],[yint1(:,1);flipud(yint1(:,2))],'k','FaceAlpha',0.1); % Prediction intervals
legend('Observed Data','GPR predictions', '95% Confidence Interval
');
I'm applying GPR on my data. However, I want to to test data on different kernels. I have written the above code to compare two GPR models with different kernels however it is giving the same result. Could you please guide how can I add different kernels and compare both.
Thanks in advance
4 Commenti
Image Analyst
il 22 Nov 2022
People can't run an image. Make it easy for people to help you. Don't make them type in all that. They just simply won't and will move on to the next question.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Risposte (1)
Drew
il 10 Gen 2023
Modificato: Drew
il 10 Gen 2023
Your data has only seven points, so this is a very small dataset. Here are some results using R2022b RegressionLearner to build Gaussian Process Regression models with various kernels. Regression Learner doc can be seen at https://www.mathworks.com/help/stats/assess-model-performance-in-regression-learner.html
In the session start dialogue, I selected "7-fold cross validation", so this is leave-one-out cross-validation. Regression Learner will train a model for each fold (each of them trained on six points, and tested on one point), and a final model trained on all 7 points. When the model is exported, it will be the final model, as described in the note at the top of this page: https://www.mathworks.com/help/stats/export-regression-model-to-predict-new-data.html
Next, I chose "All GPR Models", "Optimizable GPR", and "All Linear" from the model gallery, and ran the training. (I deleted the default tree model that was model 1). Here is a view of the results, with the models sorted by "RMSE (Validation)", where you can see that "Optimizable GPR" model has the lowest "RMSE (Validation)" among these models. The "Optimizable GPR" tries various kernel functions, as seen in the "Hyperparameter Search Range" section for model 3 in the screenshot below. In the "Optimized Hyperparameters" section you can see that the "Nonisotropic Matern 3/2" kernel function was chosen during the optimization process. You can choose which summary info and plots to view simultaneously by creating a tile layout using the small drop-down arrow in the upper right of the models plot tabs and dragging and dropping plots to the desired locations, as described at https://www.mathworks.com/help/stats/assess-model-performance-in-regression-learner.html#mw_e5cb4a5c-c14b-4b33-b7e6-bcb87b2bad1f
You can generate code to produce any of these models at the command line using the "Generate function" option in the "Export" section.
You can export any of the models to work them at the command line, using the "Export Model" option in the "Export" section.
In conclusion, Regression Learner can be used to quickly try a variety of models.
If this has answered your question, please remember to accept this answer.
0 Commenti
Vedere anche
Categorie
Scopri di più su Gaussian Process Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!