資源簡介
自己編寫的隨機梯度下降算法,附上房價預(yù)測數(shù)據(jù)集,感興趣的可以看看

代碼片段和文件信息
%隨機梯度下降算法
%導(dǎo)入訓(xùn)練集
x=[121043;116003;124003;114162;130004];
y=[400330369232540];
%設(shè)初始值
theta=[-700.065103];??
alpha=0.0000000003;
eps=0.0000001;
count=0;
finish=0;
m=5;
K=0;
while?((finish==0)&&(count<20000))
??????count=count+1;
??????J=0;
??????for?i=1:m
??????????temp1=0;
??????????for?j=1:3????????
??????????????temp1=temp1+theta(j)*x(ij);????????????????
??????????end
??????????temp2=temp1-y(i);
??????????J=J+1/2*temp2^2;
??????end
??????delta=K-J;
??????K=J;
??????fprintf(‘count=%dJ=%ftheta1=%ftheta2=%ftheta3=%f?\n‘countJtheta(1)theta(2)theta(3))
??????if?(abs(delta) ??????????finish=1;
??????else
??????????for?i=1:m;
??????????????temp1=0;
??????????????for?j=1:3
??????????????????temp1=temp1+theta(j)*x(ij);?
??????????????end
??????????????temp2=temp1-y(i);
??????????????for?j=1:3
??????????????????theta(j)=theta(j)-alpha*temp2*x(ij);
??????????????end
??????????end
??????end
end
fprintf(‘FINISH\n‘)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1012??2018-03-10?08:54??SGD.m
?????文件???????1852??2018-03-11?15:03??test.m
?????文件??????15766??2016-10-25?21:22??housing.mat
-----------?---------??----------?-----??----
????????????????18630????????????????????3
評論
共有 條評論