⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msmt_tree.m

📁 决策树算法的matlab实现
💻 M
字号:
function T = msmt_tree(A,B,maxdepth,tol,CF,min_points)
% MSMT_TREE obtains necessary information to call the function
%	msmt_tree_grow that grow the decision tree generated by the MSM-T
%	algorithm.
%	
%	T = msmt_tree(A,B,maxdepth,tol,CF) returns the decision
%		tree generated by MSM-T and puts it in a file.
%
%	T: matrix representing the decision tree.
%		(let n be the dimension of the points in set A and set B.)
%		for column j in matrix T:
%		T(1:n,j) = w (the weight vector for this particular node)
%		T(n+1,j) = theta (the threshold value for this node)
%		T(n+2,j) = lchild (index of the left child of this node)
%		T(n+3,j) = rchild (index of the right child of this node)
%		T(n+4,j) = depth of the current node
%		NOTE: if lchild = -1, then node's left child is a leaf node
%		      if rchild = -1, then node's right child is a leaf node
%	A: matrix representing set A
%	B: matris representing set B
%
%	maxdepth: maximum allowable depth of decision tree, integer >= 1
%	    	  NOTE: if maxdepth is not given, it is set to a huge
%		        positive integer.
%
%	tol: percentage allowable error in a leaf node, 0 <= tol <= 1
%	     NOTE: if tol is not given, tol = 0.0
%
%	CF: certainty factor used in pruning algorithm (see C4.5: Programs
%	    for Machine Learning by J. Ross Quinlan for more information).
%	    NOTE:  if CF is not given or CF = 0.0, then the generated
%		   tree will not be pruned.
%
%	min_points: minimum number of points such that if the number of
%		misclassified points at a decision node are less than
%		min_points, this decision node will be pruned.
%
%	NOTE: maxdepth, tol, CF, min_points are optional parameters

% This function is written to call the recursive function msmt_tree_grow,
% generating the tree, T.  msmt_tree_grow is not called directly because
% there are some parameters passed which are only used in the recursion.


% begin
A =[
 0 1 1 0 1 0 1 0 1 
 0 0 0 0 1 1 1 1 1 
 1 1 1 1 1 0 1 0 0 
 1 1 0 0 1 1 0 0 1 
 1 0 0 1 1 1 0 0 0
 1 1 1 0 0 1 0 1 0 
 0 1 0 0 0 1 1 1 1 
 0 1 0 0 1 1 1 1 1
 0 1 0 0 0 1 1 1 1
 1 0 1 1 1 1 0 1 1]
 
B=[
0
0
1
0
1
1
0
1
0
0]
global n;
if nargin < 6
	min_points = 0;
end
if nargin < 5 
	CF = 0.0;
end

if nargin < 4 
	tol = 0.0;
end
if nargin < 3
	maxdepth = round(realmax);	% big number
end

% the value of n is the dimension of the points (i.e. number of columns in
% matrix A)

n = size(A,2);

% depth is defined here to the the number of decisions made on the way
% down the tree.  so initially, the depth is 1, since we always will make
% one decision (draw one plane).

curdepth = 1;

% plant this seed and grow this tree!!!!!

T = [];
T = msmt_tree_grow(T,A,B,maxdepth,curdepth,tol);

if (CF ~= 0.0)
	T = prune_tree_C45(T,A,B,CF);
end
	
if (min_points ~= 0)
	T = prune_tree_points(T,A,B,min_points);
end








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -