Calculate the Median of the results from 100 Simulations

4 visualizaciones (últimos 30 días)
CMatlabWold
CMatlabWold el 13 de Oct. de 2021
Comentada: CMatlabWold el 14 de Oct. de 2021
Hi. I have a code where I am running a Random Forest regression. I am running it 100 times. However, I am having difficulty calculating the median of the 100 trials.
The result I am looking for is located in the variable designated "impOOB".
For each run, there should be values in impOOB variable for 5 columns. For instance:
0.427417559041683 0.00894308188405568 0.141297948087486 0.222153283589539 0.200188127397237
For 100 runs of column 1, I need the median. The same for column 2, and so forth.
My code is as follows:
n = 100;
result = zeros(n,5);
for k=1:n
X = readtable('TOPOonly.xlsx','PreserveVariableNames',true)
Y = readtable('TotalComplaintsRF.xlsx','PreserveVariableNames',true)
t = templateTree('NumVariablesToSample','all',...
'PredictorSelection','interaction-curvature','Surrogate','on');
Mdl = fitrensemble(X,Y,'Method','Bag','NumLearningCycles',200, ...
'Learners',t);
yHat = oobPredict(Mdl);
R2 = corr(Mdl.Y,yHat)^2
impOOB = oobPermutedPredictorImportance(Mdl);
impOOB(impOOB<0) = 0;
impOOB = impOOB./sum(impOOB)
result(k) =
end
I'll attach the files as well. I appreciate very much any help with this.

Respuesta aceptada

Matt J
Matt J el 14 de Oct. de 2021
Editada: Matt J el 14 de Oct. de 2021
impOOB=rand(100,5)
impOOB = 100×5
0.7604 0.5152 0.7196 0.2418 0.5420 0.8386 0.3787 0.4701 0.4692 0.7572 0.9929 0.0561 0.2087 0.1176 0.9434 0.7796 0.2491 0.1337 0.1499 0.9048 0.3695 0.1500 0.6826 0.4575 0.4751 0.6069 0.1207 0.8111 0.5832 0.3273 0.9885 0.2647 0.1840 0.9606 0.0610 0.1243 0.3249 0.5171 0.1649 0.9400 0.7085 0.7869 0.5282 0.5472 0.4634 0.7656 0.4034 0.7932 0.8618 0.5136
median(impOOB,1)
ans = 1×5
0.4813 0.4997 0.4696 0.4513 0.5518
  3 comentarios
Matt J
Matt J el 14 de Oct. de 2021
n = 100;
result = zeros(n,5);
for k=1:n
X = readtable('TOPOonly.xlsx','PreserveVariableNames',true)
Y = readtable('TotalComplaintsRF.xlsx','PreserveVariableNames',true)
t = templateTree('NumVariablesToSample','all',...
'PredictorSelection','interaction-curvature','Surrogate','on');
Mdl = fitrensemble(X,Y,'Method','Bag','NumLearningCycles',200, ...
'Learners',t);
yHat = oobPredict(Mdl);
R2 = corr(Mdl.Y,yHat)^2
impOOB = oobPermutedPredictorImportance(Mdl);
impOOB(impOOB<0) = 0;
result(k,:) = impOOB./sum(impOOB);
end
median(result,1)
CMatlabWold
CMatlabWold el 14 de Oct. de 2021
It works. Thank you very much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by