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.


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.

| cite | improve this answer | |

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