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

    %% Estimate Observation Scores of a Trained Decision Tree
%% Generate random data

% Copyright 2015 The MathWorks, Inc.

rng(0,'twister') % 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 prediction scores
[~,score] = predict(tree1,X(1:10));
[score X(1:10,:)]