Calculate the Median of the results from 100 Simulations

2 次查看(过去 30 天)
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.

采纳的回答

Matt J
Matt J 2021-10-14
编辑:Matt J 2021-10-14
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 个评论
Matt J
Matt J 2021-10-14
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by