决策树cart算法程序matlab
(2013-04-14 15:30:52)分类: 经典算法/数据挖掘/神经网络 |
function D = CART(train_features, train_targets, params,
region)
% Classify using classification and regression
trees
% Inputs:
% features - Train features
% targets - Train
targets
% params - [Impurity type, Percentage of incorrectly assigned
samples at a node]
%
Impurity
can be: Entropy, Variance (or Gini), or
Missclassification
% region - Decision
region vector: [-x x -y y number_of_points]
%
% Outputs
% D - Decision sufrace
[Ni, M] =
size(train_features);
%Get parameters
[split_type, inc_node] =
process_params(params);
%For the decision region
N
=
region(5);
mx
= ones(N,1) * linspace
(region(1),region(2),N);
my
= linspace
(region(3),region(4),N)' * ones(1,N);
flatxy
= [mx(:), my(:)]';
%Preprocessing
[f, t, UW, m] = PCA(train_features,
train_targets, Ni, region);
train_features = UW * (train_features -
m*ones(1,M));;
flatxy
= UW *
(flatxy - m*ones(1,N^2));;
%Build the tree recursively
disp('Building tree')
tree
= make_tree(train_features, train_targets, M,
split_type, inc_node, region);
%Make the decision region according to the
tree
disp('Building decision surface using the
tree')
targets = use_tree(flatxy, 1:N^2,
tree);
D = reshape(targets,N,N);
%END
function targets = use_tree(features, indices,
tree)
%Classify recursively using a tree
if isnumeric(tree.Raction)
else
end
%END use_tree
function tree = make_tree(features, targets, Dlength,
split_type, inc_node, region)
%Build a tree recursively
if (length(unique(targets)) == 1),
end
[Ni, M] = size(features);
Nt =
unique(targets);
N =
hist(targets, Nt);
if ((sum(N < Dlength*inc_node) == length(Nt) -
1) | (M == 1)),
else
end
前一篇:决策树c4.5程序matlab
后一篇:BP神经网络Matlab实例