Solved – Custom error function for randomForest R package

machine learningrrandom forest

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

randomForest(value*weight~.,...)

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

Best Answer

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.