View the tree ensemble trained by fitcensemble

10 visualizzazioni (ultimi 30 giorni)
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??

Risposte (1)

Puru Kathuria
Puru Kathuria il 6 Mar 2020
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 Commento
Elena Casiraghi
Elena Casiraghi il 6 Mar 2020
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?

Accedi per commentare.

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by