www.gusucode.com > stats 源码程序 matlab案例代码 > stats/PosteriorProbabilityDefinitionForClassificationTreeExample.m

    %% Posterior Probability Definition for Classification Tree
%% Generate 100 random points

% Copyright 2015 The MathWorks, Inc.

rng(0) % For reproducibility
X = rand(100,1);
Y = (abs(X - .55) > .4);
tree = fitctree(X,Y);
view(tree,'Mode','graph')
%% Prune the tree
tree1 = prune(tree,'Level',1);
view(tree1,'Mode','graph')
%% Compute the prediction scores
[~,score] = predict(tree1,X(1:10));
[score X(1:10,:)]