Regression Learner: One column for x-axis; multiple for y-axis ?
Show older comments
If I have a Matrix like this:

Is it possible, to use the first column for my "x-axis" and ALL of the other columns for my "y-axis"?
I need a linea regression (a plot), that fits all my points at best. Like this:

Now i don't know, how to tell MATLABs Regression Learner to do that. The only option to do seems like taking the last column for the y-axis and all the other as x-Axis. However then only one column at a time as x.
Greetings and Thank you.
2 Comments
Alan Stevens
on 29 Jul 2020
Edited: Alan Stevens
on 29 Jul 2020
You can save the "y" data as a matrix, Y, (size 11x19 by the looks of it). If you then just plot(x,Y,'*') Matlab will automatically plot the whole lot as in your hand drawn picture.
dpb
on 29 Jul 2020
I don't know the regression learner tool; I can imagine the title would be such that it does expect only single input/single output variables.
You don't need it to just fit a regression model; for the simplest case w/o diagnostics and all that, simply
x=M(:,1);
y=M(:,2:end);
b=polyfit(x,y(:),1);
yh=polyval(b,[min(x) max(x)]);
will give you the coefficients and the two endpoints of the fitted line.
NB HOWEVER: If you include the group of zeros at x=0 and x=2 in the fit, you'll not get a line like you've drawn by hand/eye but one that will come much closer to going through the origin and steeper slope.
Depending upon which toolboxen you have, there are other higher-level fitting routines available.
I see the documentation for the statistics toolbox that contains RegressionLearner doesn't deign to even mention simple linear regression; the "Linear Regression" link just jumps into multivariate and all. That doesn't mean you can't still just use the "LinearModel" tool/object, though.
Sometimes TMW can't see the trees for the forest in the documentation...
Answers (0)
Categories
Find more on Support Vector Machine Regression in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!