Closed maxujie closed 7 years ago
这里有一个已经写好的 MATLAB LDA 代码,并没有钦点的意思,不过可以试试看。。
Update: 找了一些相关资料,看起来这个东西并不是实现降维的 LDA?
当然如果 LDA 做不了的话 PCA 也可以..
之前看SVM的时候,好多用的是libSVM,这个训练的代码和MATLAB自带代码相同,换个库就可以用,不用改代码,感觉可以试试
这里有一段看上去可以直接用的 LDA 降维代码(并不知道是不是真的可以直接用)
http://people.kyb.tuebingen.mpg.de/pgehler/code/index.html
function [d,alg] = training(a,d)
X = get_x(d);
[nPoints,nDims] = size(X);
if size(d.Y,2) == 1 | max(d.Y) > 1
nClasses = max(d.Y);
if nClasses < 2
error('Only 1 class given');
end
else
nClasses = size(d.Y,2);
end
dataMean = mean(X,1);
Sw=zeros(nDims,nDims);
Sb=zeros(nDims,nDims);
for i=1:nClasses
if size(d.Y,2) == 1 % if labels are given as 1,2,3,4...
ind = find(d.Y==i);
else % labels are 0 0 1 0 0 ...
ind = find(d.Y(:,i)==1);
end
if numel(ind) == 0 % empty class: ignore
continue;
end
classMean = mean(X(ind,:));
Sw = Sw + cov(X(ind,:),1);
Sb = Sb + numel(ind)*(classMean-dataMean)'*(classMean-dataMean);
end
[U,D,V] = svds(Sw\Sb,a.dim);
alg = a;
alg.V = V;
alg.b = -dataMean*V;
d = test(alg,d);
function a = lda(hyper)
%====================================================================
% LDA - Fisher Linear Discriminant Analysis
%====================================================================
%
% Hyperparameters, and their defaults
% dim=2 -- dimensions to project on
%
% Model
% V -- projection matrix
% b -- offset
%
% Methods:
% train,test,plot
%
% Example:
%
% load /spider/demos/data/yeastXYmc5norm.mat
% [dout,e] = train(lda('dim=2'),data(X,Y));
% plot(dout)
%
%=============================================================================
% Reference : chapter 3 - Mutiple Discriminant Analysis (Duda&Hart&Stork)
% Author : Richard O.Duda, Peter E. Hart and David G. Stork
% Link : http://www.amazon.com/exec/obidos/tg/detail/-/0471056693/002-6279399-2828812?v=glance
% Code by : Peter Gehler
%=============================================================================
a.dim = 2;
a.V = [];
a.b = [];
p=algorithm('lda');
a= class(a,'lda',p);
if nargin==1
eval_hyper;
end
Discriminant Analysis 感觉Matlab自带函数干的就是这事...
@cghahn 嗯我同意,之前我理解错了,以为 LDA 是前面的那个东西。
本来想显式地实现 LDA 降维是觉得音频特征、情感特征、场景特征这些统计性质不同的特征各自相对大小和维数不同,重要性也不一样,在分类的时候如果一起处理的话会影响效果。
不过直接用 MATLAB 自带函数如果效果好的话那也可以。
发现了一个很有用的库
之前测试了一下发现 MATLAB 的 SVM 分类器在训练的时候有很大概率不能收敛,所以下周可能需要考虑用第三方 SVM,或者加入 LDA 这样的降维方法让 SVM train 起来更容易一些