資源簡介
參考我的個人博客:
分類器設計之logistic回歸分析
http://blog.csdn.net/ranchlai/article/details/10022637
代碼片段和文件信息
%
%?Liscense?Notification?2013
%
%?Redistributions?in?source?and?binary?forms?with?or?without
%?modification?are?totally?FREE?provided?that?you?keep?this?keep?this
%?notification
%
%??Descritption:?This?package?demostrates?how?to?use?the?logistic
%??regression?for?classfication?of?2D?data.
%??Author:??Ranch?Lai?(ranchlai@hotmail.com)
%??Release?date:?Aug?17?2013
%/
%%
clc;
clear;
close?all;
%%
x?=?-10:0.1:10;
y?=?1./(exp(-x)+1);
plot(xy‘g-x‘);
title(‘logistic?function‘);
xlabel(‘x‘);ylabel(‘y‘);
%%?generate?random?data
shift?=?2;
n?=?2;%2?dim
%y?=?1./exp(-w‘*x+b)
N?=?200;
x?=?[randn(nN/2)-shift?randn(nN/2)*2+shift];
y?=?[zeros(N/21);ones(N/21)];
%show?the?data
figure;
plot(x(11:N/2)x(21:N/2)‘rs‘);
hold?on;
plot(x(11+N/2:N)x(21+N/2:N)‘go‘);
title(‘2d?training?data‘);
%%
%training..
[wbcost]?=?logistic_train(xy1e-6100);
%%
disp(‘training?ended‘);
figure;
plot(cost‘g-s‘);
xlabel(‘iterate‘);
ylabel(‘cost‘);
set(gca‘YScale‘‘log‘);
title(‘convergence?curve‘);
%%?plot?the?training?data
figure;
plot(x(11:N/2)x(21:N/2)‘rs‘);
hold?on;
plot(x(1N/2+1:N)x(2N/2+1:N)‘go‘);
%%?visualize?the?classification?aera
hold?on;
for?x?=?-shift*5:0.5:shift*5
????for?y=-shift*5:0.5:shift*5
????????if?1/(1+exp(w(1:2)‘*[x;y]+b))?>?0.5
????????????plot(xy‘g.‘);
????????else
????????????plot(xy‘r.‘);
????????end
????end
end
title(‘classification?result?on?training?data‘);
%%
????????
????????
評論
共有 條評論