- 积分
- 11
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-11-16
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-11-16 19:44:26
|
显示全部楼层
%训练过程 Logistic_solve.m
function [beta,rate] = Logistic_solve(x,y,step_in) %回归系数beta,正确率rate
step = step_in;
x_training = x;
y_training = y;
s = size(x_training); %s(1)=N 样本数
p = zeros(s(1),1); %初始化p
beta = zeros(s(2),step+1); %初始化beta=0
W = zeros(s(1)); %初始化W=1
L=0;
for t=1:step %第2步后,第3步无解,故1步后的beta就是最终解
for i=1:s(1)
p(i,1) = exp(beta(:,t)'*x_training(i,1:s(2))') / (1+exp(beta(:,t)'*x_training(i,1:s(2))'));
W(i,i) = p(i,1)*(1-p(i,1));
end
z = x_training*beta(:,t) + inv(W)*(y_training - p);
beta(:,t+1) = inv(x_training'*W*x_training) * x_training'*z;
end
beta=beta(:,t); %???
%标准化y,算误差点数
for i=1:s(1)
if p(i)>0.5
p(i)=1;
end
end
L = sum(abs(p - y_training)); %若判断正确,则p == y_training,L==0
rate = (s(1)-L)/s(1)*100; %正确率
|
|