- Each row of Tbl corresponds to one observation, and each column corresponds to one variable.
How do I fit a 3rd order polynomial Basis using fitrgp?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
FsC
am 30 Mai 2024
Kommentiert: Star Strider
am 2 Jun. 2024
Hello,
I am trying to fit a 3rd order polynomial basis using fitgrp for my signal (1x1503). From the instructions, it looks like I would pass hfcn but don't quite understand how to implement this for the 3rd order polynomial. How would I do this?
Here is code but at the moment it is only implementing a quadratic:
t_observed = (0:length(dodWavelet(:,1))-1)/10;
y_observed = dodWavelet(:,1);
gprMdl1 = fitrgp(t_observed',y_observed,'Basis',"pureQuadratic");
[ypred1] = predict(gprMdl1,t_observed');
0 Kommentare
Akzeptierte Antwort
Star Strider
am 30 Mai 2024
Bearbeitet: Star Strider
am 30 Mai 2024
From the documentation, using a table as input:
So the data must be column-oriented.
Taking a clue from the 'pureQuadratic' function, see if this does what you want —
dodWavelet = randn(1,1503).' + sin(2*pi*(0:1502).'/500); % Create Data (Note Transposition To Column Vector)
t_observed = (0:length(dodWavelet(:,1))-1)/10;
y_observed = dodWavelet(:,1);
hfcn = @(X) [ones(size(X)) X X.^2 X.^3];
B0 = rand;
gprMdl1 = fitrgp(t_observed',y_observed,'Basis',hfcn, 'Beta',B0);
format long
Coefficients = gprMdl1.Beta
format short
[ypred1,ysd1, yint1] = predict(gprMdl1,t_observed');
figure
hp1 = plot(t_observed, y_observed, '.', 'DisplayName','Data');
hold on
hp2 = plot(t_observed, ypred1, '-r', 'DisplayName','Regression');
hp3 = plot(t_observed, yint1, '--r', 'DisplayName','95% Confidence Limits');
hold off
grid
legend([hp1 hp2 hp3(1)], 'Location','best')
It seems to work and produce a reasonable result.
EDIT — (30 May 2024 at 22:03)
Added ‘Coefficients’ assignment to display them.
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Gaussian Process Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!