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!