scikit-learn/scikit-learn — pull request #2937 by andosa (2014-03-05 23:04:56+00:00)
Title: Option to return full decision paths when predicting with decision trees or random forest

A very useful feature for decision trees is the option to access the full decision path for a prediction, i.e. the path from root to leaf for each decision.
This enables to interpret the model in the context of data in a very useful way. In particular, it allows to see exactly why the tree or forest arrived at a particular result, breaking down the prediction into exact components (feature contributions). This is much needed in certain application areas, for example in credit card fraud detection it is important to get an understanding why the model labels a transaction as fraudulent.

The pull request implements a predict option for random forest and decision tree: when *return_paths* keyword argument is set to True, paths are returned instead of predictions. I have not added docstrings yet, I assume the API might be expected to be different (another method instead of keyword argument to predict?)

In addition, there is a change to store values at each node, not just the leaves (useful when interpreting the tree).