Matlab Multiple Regression
I have this set of variables:
N = 250;
% independent variables[0..10]
x_1 = rand(N,1) * 10;
x_2 = rand(N,1)开发者_开发知识库 * 10;
y = ones(N,1); % regresssion variable
y((x_1 + x_2 + rand(N,1) * 2) <= 11) = 2;
I want to make two-var regression in matlab, but do not know how to do this, can somebody helps me? The result of linear or polynomial regression must be line between this two classes, stored in y.
One or more 'independent' variables, it's the same. Just as an example few ways to solve:
>>> X= [x_1 x_2];
>>> X\ y
ans =
0.10867
0.11984
>>> pinv(X)* y
ans =
0.10867
0.11984
See more of \ and pinv.
Matlab do have many other ways to solve least squares. You may like to elaborate more on your specific case, in order to find the most suitable one. Anyway, above documentation is a good starting point for you.
Edit:
Some general information on least squares
worthwhile to read are wiki and mathworks
精彩评论