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.
0 个评论
采纳的回答
Matt J
2021-10-14
编辑:Matt J
2021-10-14
impOOB=rand(100,5)
median(impOOB,1)
3 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!