Multivariate Linear Regression code
1 次查看(过去 30 天)
显示 更早的评论
In my hand, 30 samples of 4 features and 30 outputs. i want to learn the regression equation of these as;
theta=theta(0) + theta(1) x(1)+ ... + theta(4) x(4)
I am using gradient descent algorithm for this regression analysis. there are three main equations;
for m=1:30;
cost function= J(theta(0)..,theta(4))=1/2m * sum(h(theta)x - y) ^2
%sum is from 1 to m. x and y are from 1 to m.
theta(j) := theta(j) - alpha (derivative/derivative theta(j)) J(theta(j)
Thanks
回答(2 个)
bym
2012-5-18
I really do not understand your question, but perhaps this is what you are looking for:
x = rand(30,4);
>> y = rand(30,1);
>> X = [ones(30,1) x];
>> theta = X\y
theta =
0.6702
0.1183
-0.4163
-0.1072
-0.1355
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!