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!