代码托管在github
https://github.com/sofiathefirst/matlabdemo/tree/master/02Linear_regressin_demo
x=[-2:0.1:2];
y = 4*x;
z=normrnd(0,0.6,1,41);
y = y+z;
w = -5;
plot(x,y,'.')
%hold on
for i =[1:1000]
d=w*x*x' - y*x';
if(abs(d)<1)
break;
end
w = w-0.004*d
plot(x,y,'.',x,w*x)
pause(0.1)
end


本演示通过Matlab代码展示了如何使用梯度下降法进行线性回归分析。代码中定义了数据集,并通过迭代更新权重参数来拟合一条最佳直线。演示过程中还包括了可视化步骤,可以观察到权重调整的过程。
13万+

被折叠的 条评论
为什么被折叠?



