TreeBagger with Random Seed - different results

8 views (last 30 days)
Heiko
Heiko on 17 Feb 2021
Answered: 1 1 on 11 Jan 2023
Hello,
everytime a function containing the following lines is called from scratch, it returns slightly different results, even though the seed is always set. It only returns the same results, when calling TreeBagger within the same function multiple times, but not when cold-calling the function. I have tried different ways to initialize the seed, but none of them works.
rng('default');
mdl = TreeBagger(20, X, y, 'Method', 'classification', 'OOBPredictorImportance', 'on');
result = mdl.OOBPermutedPredictorDeltaError;

Answers (1)

1 1
1 1 on 11 Jan 2023
HI.
I had the same problem.
Now you may have solved the problem, but I'll leave an answer for those with the same question.
try to add this example to your code.
s = RandStream('mlfg6331_64'); % has substreams
opts = statset('UseParallel',true,...
'Streams',s,'UseSubstreams',true);
RF_model = TreeBagger(300,TRAIN_X,TRAIN_y,'Method','classification','Options',opts);
Related Links

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!