View the tree ensemble trained by fitcensemble

조회 수: 10 (최근 30일)
Elena Casiraghi
Elena Casiraghi 2020년 2월 27일
댓글: Elena Casiraghi 2020년 3월 6일
Dear, let's suppose I'm training a bagged tree ensemble on the 40 sampe points (29 features per sample)
The GT labels are in the var labels.
I gat a tree mdlRF as follows:
dataSel = rand(40, 29); % just a toy example
labels = logical(randi(1,29,1)); % just a toy example
t = templateTree('PredictorSelection','interaction-curvature','Surrogate','on', ...
'Reproducible',true); % For reproducibility of random predictor selections
mdlRF = fitcensemble(dataSel,labels,'Method','Bag', ...
'CategoricalPredictors',[false true true true true true], 'PredictorNames', vars,...
'NumLearningCycles',30,'Learners',t);
If the trained learner were a simple tree I could have viewed it in graph /text mode with the command:
view(mdlRF, 'Mode', 'graph')
Is there an alternative way to view how the mdlRF makes the decision??

답변 (1개)

Puru Kathuria
Puru Kathuria 2020년 3월 6일
Hi,
I understand that you want to visualize your ensemble after training it on a dataset. You can try replacing 2nd line of code with the following line.
labels = logical(randi(1,40,1)); % Training data points (X) should be equal to training labels (Y)
And the last line with the following line.
view(mdlRF.Trained{1}.CompactRegressionLearner,'Mode','graph'); % Visualising
This might meet your requirements and help you visualize your model.
  댓글 수: 1
Elena Casiraghi
Elena Casiraghi 2020년 3월 6일
Sorry Puru!
The code was wrong in the number of labels
dataSel = rand(40, 29); % just a toy example: 40 points
labels = logical(randi(1,40,1)); % just a toy example: 40 labels
t = templateTree('PredictorSelection','interaction-curvature','Surrogate',1, ...
'Reproducible',true);
% For reproducibility of random predictor selections
% Use surrogate = 1 to generate surrogate 1 branch for each split: when one value is NaN in the data, the surrogate branch i used
numTrees = 7;
% train a random forest with 7 trees
mdlRF = fitcensemble(dataSel,labels,'Method','Bag', ...
'CategoricalPredictors',[false true true true true true], 'PredictorNames', vars,...
'NumLearningCycles',numTrees,'Learners',t);
for numTree = 1: numTrees
view(mdlRF.Trained{1}, 'Mode', 'graph');
end
This show all the seven trees, BUT it does not show the alternative (surrogate) branches that are used when a Nan Value is present.
How can I do that?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Classification Ensembles에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by