TreeBagger with Random Seed - different results

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;

回答(1 个)

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

产品

版本

R2016a

提问:

2021-2-17

回答:

1 1
2023-1-11

Community Treasure Hunt

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

Start Hunting!

Translated by