I am a R beginner. Is there a way to specify custom error function with Random Forests in R? For example, say my training data is ,,, so on and my error for any given set needs to normalize the weights and then calculate the mean of absolute error. So my error for each data point is (predicted-actual)*normalized_weight.

I don't know how to specify this with the randomForest function. I could do something like


-- but this doesn't normalize the weight. Any one has any idea?


1 Answer 1


There's no way to specify an error function for the standard randomForest implementation. It is possible to supply a custom splitting function to the function rpart which generates a single regression tree, and then to use the ipred package to perform bootstrap aggregation, giving a bagged regression forest, but this is still not a full random forest, as there is no random feature selection taking place.

Unfortunately, your best bet here is probably to write your own random forest code, or possibly to modify the existing implementation, if you're happy digging around in C code.

  • $\begingroup$ @martin When you say "supply a custom splitting function to the function rpart", do you mean supply your own choice of impurity measure? How could one do this with rpart - dig around in the C code? $\endgroup$
    – BarkleyBG
    Commented Oct 7, 2016 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.