# Random Forests interpretability [duplicate]

This question already has an answer here:

I have been using the sklearn RandomForestClassifier to solve a binary classification problem.

For a particular sample prediction, I would like to be able to know how to change the features values to make the prediction change.

E.g. let's say I have an entry with [size = 15, width = 8, height = 13] and the model gives me aprobability = 0.9 to be of class 1. What I would like to be able to say is "change size from 15 to 10" and then your probability=0.1 for example.

Then optimally, what I would like is the smallest "gradient" in the features values to pass from one class to another (or the one that gives the most change in probability).

Maybe I'm wrong, but from what I've read the packages LIME and treeinterpreter do not provide this kind of information.

## marked as duplicate by Sycorax, Jan Kukacka, Tim♦Sep 26 '18 at 7:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

## 1 Answer

A random forest isn't suited very well to this, as each individual tree partitions the space up into disjoint regions of space and thus at some granular level, the target variable always changes discretely.

For example, at x=0.8 and x=0.9, y might equal 1, and then at x=1 and x=1.1, y might equal 1.5. How is your derivative then defined, even in terms of finite differences?

Analytical models, such as logistic regression and neural networks allow you to differentiate the target variable with respect to any given feature for the current parameter values to calculate such a derivative. I would suggest that if calculating the derivative is key to the problem you're solving, you might try using an analytic classifier. It might be worth investing some time into seeing whether logistic regression/a neural network perform as well as a random forest w.r.t whatever loss condition you're using under cross-validation.

If both perform worse than a random forest, you can weigh up whether the ability to differentiate is a worthwhile trade-off for lower accuracy.