% A demo to LDA(Linear Discriminant Analysis)
% include a figure to discribe it
% Note:the demo data is watermelon_3.0_alpha.csv
% Liu Jingchang 2016/3/9
% log:
%% get the coefficients of LDA
% get data
data = csvread('.\watermelon_3.0_alpha.csv',1,1);
% get positive and negative class
y = data(:,end);
positive_class = data(find(y==1),1:end-1);
negative_class = data(find(y==0),1:end-1);
% get the average vector of each class
mu_1 = mean(positive_class);
mu_0 = mean(negative_class);
% get the between-class scatter matrix
S_b = (mu_0-mu_1)' * (mu_0-mu_1);
% get the within-class scatter matrix
% get the within-class scatter matrix of positive class
temp1 = size(positive_class);
n = temp1(1);
mu_0_repmat = repmat(mu_0,n,1);
delta_0 = (positive_class - mu_0_repmat)' * (positive_class - mu_0_repmat);
% get the within-class scatter matrix of negative class
temp2 = size(positive_class);
n = temp2(1);
mu_1_repmat = repmat(mu_1,n,1);
delta_1 = (positive_class - mu_1_repmat)' * (positive_class - mu_1_repmat);
%
S_w = delta_0 + delta_1;
% get the eigrnvalue of (S_w)^-1 * S_b
eig_value = sort(eig(inv(S_w)*S_b),'descend')
%% figure to discrobe LDA
% plot the scateer in different style to distinguish class
plot(positive_class(:,1),positive_class(:,2),'r+',...
negative_class(:,1),negative_class(:,2),'y*')
hold on
% plot the line of LDA
t = 0:0.01:1;
plot(t,eig_value(1:end-1)'*t)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Matlab实现LDA(完整源码).zip (9个子文件)
Graduation Design
watermelon_3.0_alpha.csv 299B
LDA_fun.asv 166B
.gitattributes 378B
LDA_demo.m 1KB
.gitignore 649B
LDA_demo.asv 1KB
iris.csv 2KB
abalone.csv 128KB
LDA_fun.m 1KB
共 9 条
- 1
资源评论
学术菜鸟小晨
- 粉丝: 1w+
- 资源: 4960
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功