MATLAB: How to specify loss function when using ‘fitrensemble’ function

ensemblefitrensemblefunctionlossregressionStatistics and Machine Learning Toolbox

I am using "fitrensemble" function from MATLAB Statistics and Machine Learning Toolbox for a machine learning application. In the documentation, the default loss function is set to mean square error, how can I specify a different loss function?

Best Answer

"fitrensemble" function has different algorithms/solvers and the loss depends on the type of algorithm/solver you select for the training. For MATLAB R2019a, more details on the ensemble algorithms can be found at: https://www.mathworks.com/help/releases/R2019a/stats/ensemble-algorithms.html
For example, you can use the following code to specify algorithm/solver:
>> fitrensemble(model, 'Method', 'Bag')
Once a model is trained, you can evaluate the model with different loss functions via "resubLoss" function. However, this function cannot change the loss function for training.
The documentation for "resubLoss" function can be found here: https://www.mathworks.com/help/releases/R2019a/stats/regressionensemble.resubloss.html
Related Question