资源简介
matlab版的信息增益算法实现
代码片段和文件信息
function tree = InformationGain(a)
targets = a(:end);
targets = targets‘;
a = a(:1:end-1);
patterns = a‘;
[Ni L] = size(patterns);
%Nu = 1000;
discrete_dim = zeros(1Ni);
for i = 1:Ni
Ub = unique(patterns(i:));
Nb = length(Ub);
%This is a discrete pattern
discrete_dim(i) = Nb;%记录每列属性独一无二的样本的长度
end
% Build a tree recursively
% patterns - Train patterns训练集D (the number of features) * (the number of samples)
% targets - Train targets 1*(the number of samples)训练集D的类数
% inc_node - Stop building a subtree if its total samples are less than inc_node,
% discrete_dim - 1*(the number of features). 0 entries for continuous features
% [NiL]= size(patterns);%Ni-the number of features,L-the number of samples)
Uc= unique(targets);%训练集D的类数,并从小到大排序
for i = 1:length(Uc)
Pnode(i) = length(find(targets == Uc(i))) / L;
%disp(find(targets == Uc(i)));
end
Inode = -sum
评论
共有 条评论