Change objective function for hyperparameter optimization in regression ensembles
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi
I want to change the objective function which is minimized during hyperparameter optimization for regression ensembles. The objective function is by default: log(1 + mse). Is it possible to change it to just Mean Absolute Error (MAE)? This value is more intuitive i think.
If possible, how should I call fitrensemble() with 'mae' as objective function?
BR /Tobias Pahlberg
댓글 수: 0
채택된 답변
Don Mathis
2017년 3월 31일
편집: Don Mathis
2017년 3월 31일
'fitrensemble' doesn't support MAE, but you can use 'TreeBagger' to do what you want. TreeBagger fits a random forest and supports quantile prediction, which can be used to compute MAE. Using MAE doesn't affect how the tree is built, but you can still optimize hyperparameters with MAE as the objective.
TreeBagger doesn't have built-in hyperparameter optimization so you need to use the 'bayesopt' function. Here's a script that does it. Paste it into an editor to run it. Note that it contains a local function definition.
% load a dataset
load carsmall
X = table(Acceleration,Cylinders,Displacement,Horsepower,Mfg,Model_Year,Weight,MPG);
% Define some variables to optimize
Hyperparameters = [optimizableVariable('MinLeafSize',[1,20], 'Type','integer');
optimizableVariable('NumPredictorstoSample', [1,width(X)-1], 'Type','integer')];
% Define the objective function to be the out-of-bag MAE.
fun = @(hparams)oobMAE(hparams,X); % It must be a function of only the hyperparameters.
% Call bayesopt to optimize MAE
results = bayesopt(fun, Hyperparameters);
% Look at the best hyperparameters found
bestHyperparameters = bestPoint(results)
% Fit a "final" model to the full dataset using the best hyperparameters
FinalModel = TreeBagger(300,X,'MPG','Method','regression',...
'MinLeafSize', bestHyperparameters.MinLeafSize,...
'NumPredictorstoSample', bestHyperparameters.NumPredictorstoSample)
% Define a function to fit a random forest of 300 trees and return out-of-bag MAE
function MAE = oobMAE(params,X)
randomForest = TreeBagger(300,X,'MPG','Method','regression',...
'OOBPrediction','on',...
'MinLeafSize', params.MinLeafSize,...
'NumPredictorstoSample', params.NumPredictorstoSample);
MAE = oobQuantileError(randomForest); % Uses the median by default.
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Regression Tree Ensembles에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!