📄 c4_5testfun.m
字号:
%C4_5TestFun.m
%Shiliang Sun (shiliangsun@gmail.com), Apr. 8, 2007
%Using the learned 4.5 decision tree to classify samples
%This code is based on the C4_5.m file from "Classification Toolbox for Matlab"
%(http://www.yom-tov.info/cgi-bin/list_uploaded_files.pl). Several bugs have been fixed.
function targets = C4_5TestFun(patterns, tree, discrete_dim)
%Classify recursively using a tree
% patterns - Test patterns, (the number of features) * (the number of samples)
indices = 1:size(patterns,2);
targets = zeros(1, size(patterns,2));
if (tree.dim == 0)
%Reached the end of the tree
targets(indices) = tree.child;
return
end
%This is not the last level of the tree, so:
%First, find the dimension we are to work on
dim = tree.dim;
dims= 1:size(patterns,1);
dims(dim)=[]; %ssl
%And classify according to it
if (discrete_dim(dim) == 0)
%Continuous pattern
in = indices(find(patterns(dim, indices) <= tree.split_loc));
if isempty(dims)
targets(in)=tree.child(1);
else
targets(in) = C4_5TestFun(patterns(dims, in), tree.child(1), discrete_dim(dims));
end
in = indices(find(patterns(dim, indices) > tree.split_loc));
if isempty(dims)
targets(in)=tree.child(2);
else
targets(in) = C4_5TestFun(patterns(dims,in), tree.child(2), discrete_dim(dims));
end
else
%Discrete pattern
Uf = unique(patterns(dim,:));
for i = 1:length(Uf),
in = indices(find(patterns(dim, indices) == Uf(i)));
if isempty(dims)
targets(in)=tree.child(i);
else
targets(in) = C4_5TestFun(patterns(dims, in), tree.child(i), discrete_dim(dims));
end
end
end
%END use_tree
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -