-
大小: 32KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-02-12
- 语言: Matlab
- 标签: Logistic regression 分类
资源简介
二分类逻辑回归matlab代码,运行有效,包含图形说明。
代码片段和文件信息
% Descritption: This package demostrates how to use the logistic
% regression for classfication of 2D data.
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;
p
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1207 2014-08-19 17:09 2d logistic regression\2d logistic regression demo\demo_logistic.asv
文件 1251 2014-08-19 17:11 2d logistic regression\2d logistic regression demo\demo_logistic.m
文件 340 2014-08-19 18:34 2d logistic regression\2d logistic regression demo\logistic_cost.asv
文件 340 2014-08-19 18:39 2d logistic regression\2d logistic regression demo\logistic_cost.m
文件 324 2014-08-19 18:44 2d logistic regression\2d logistic regression demo\logistic_predict.asv
文件 504 2013-08-17 14:05 2d logistic regression\2d logistic regression demo\logistic_predict.m
文件 1440 2014-08-19 17:14 2d logistic regression\2d logistic regression demo\logistic_train.asv
文件 1470 2014-08-19 17:17 2d logistic regression\2d logistic regression demo\logistic_train.m
文件 13912 2013-08-17 12:27 2d logistic regression\2d logistic regression demo\figure\classification.png
文件 4540 2013-08-17 12:27 2d logistic regression\2d logistic regression demo\figure\convergence.png
文件 4953 2013-08-17 12:29 2d logistic regression\2d logistic regression demo\figure\logisticfunction.png
文件 6897 2013-08-17 12:28 2d logistic regression\2d logistic regression demo\figure\trainingdata.png
评论
共有 条评论