imbs-hl / timbR

Tree interpretation methods based on ranger
10 stars 5 forks source link

alternative code in measure_distances(... "terminal nodes" ...) suitable for prob. estimating forests #5

Closed s81320 closed 2 years ago

s81320 commented 3 years ago

If one would replace the loop to calculate the matrix term_node at https://github.com/imbs-hl/timbR/blob/757f0f9f9ef49e36e616d7754649c82c24dfa2ea/R/measure_distances.R#L141 by term_node <- matrix(data = NA , nrow = nrow(test_data) , ncol = rf$num.trees) the code would be simpler, faster and could also be used for ranger random forests of type probability estimation, like

rf <- ranger(Species ~ . , data = iris , write.forest=TRUE # default , num.trees = 10 , probability = T # this is for probability estimation )

animusnaturae commented 3 years ago

Thank you very much for suggesting an easier way to calculate the terminal nodes matrix. Unfortunately your comment seems to be incomplete. I am really looking forward, to see your solution.

animusnaturae commented 3 years ago

I think I figured it out myself. You probably wanted to suggest to determine the terminal nodes by using predict.ranger(rf, data = test_data, type = "terminalNodes") Thank you very much for this suggestion which I already included.