- https://www.mathworks.com/help/stats/regressiontree.resubloss.html
- https://www.mathworks.com/help/stats/classificationsvm.resubloss.html
how to set up error function other than MSE in regression or classification training model
4 次查看(过去 30 天)
显示 更早的评论
when training a regression tree or SVM model, the default error function is MSE. How do I change it to a customized function more suitable to my application? I didn't find such an option parameter in fitrensemble or fitrsvm function.
0 个评论
回答(1 个)
Brahmadev
2023-9-12
Hi Jie,
I understand that you would like to use a custom error function in Regression Tree and Support Vector Machines. You can use the "resubLoss" function for the same. The "LossFun" parameter is used for defining the custom error function using the syntax below.
L= resubLoss(tree,'Subtrees',subtreevector,'LossFun','lossfun') % for RegressionTree
L = resubLoss(Mdl,'LossFun','lossfun') % for SVM
Here, “lossfun” is a custom loss function with the following function definition
function loss = lossfun(Y,Yfit,W) % for RegressionTree
% Y is an N-element vector representing the observed response.
% Yfit is an N-element vector representing the predicted responses.
% W is an N-element vector representing the observation weights.
% The output loss should be a scalar.
function lossvalue = lossfun(C,S,W,Cost) % for SVM
% C is an n-by-K logical matrix with rows indicating the class to which the corresponding observation belongs.
% S is an n-by-K numeric matrix of classification scores.
% W is an n-by-1 numeric vector of observation weights.
% Cost is a K-by-K numeric matrix of misclassification costs.
In addition to building custom function for error calculation, "Classification Learner" App also provides many inbuilt loss functions such as Binomial deviance, Quadratic loss, Logit loss, Hinge loss and many more.
You can refer to the MathWorks Documentation of “resubLoss” using the links below for more information:
Hope this helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!