title: using decision_path in Decision Tree in Python
body: <p>I want to retrieve the path each instance takes in decision tree or RandomForest.
  for instance, I need such an output:</p>
  
  <pre><code># 1  1 3 4 8 NA NA
  # 2  1 2 5 7 11 NA
  # 3  1 3 4 9 10 13
  # 4  1 3 4 8 NA NA
  # etc
  </code></pre>
  
  <p>It means that instance #1 passes the path from node 1, 3, 4 and ended in terminal node 8 and so forth. It is obvious that the path length of some instances is shorter than others.</p>
  
  <p>I used <code>decision_path</code> but it gives a sparse matrix which I can not understand and find such a path. Even I cannot read the output. It is the sample code for <code>Iris</code> database:</p>
  
  <pre><code>from sklearn.datasets import load_iris
  iris = load_iris()
  import numpy as np
  ytrain = iris.target
  xtrain = iris.data
  from sklearn.tree import DecisionTreeClassifier
  dtree = DecisionTreeClassifier()
  fitted_tree = dtree.fit(X=xtrain,y=ytrain)
  predictiontree = dtree.predict(xtrain)
  fitted_tree.decision_path(xtrain)
  </code></pre>
  
  <p>The output is this: </p>
  
  <pre><code>&lt;150x17 sparse matrix of type '&lt;class 'numpy.int64'&gt;'
  with 560 stored elements in Compressed Sparse Row format&gt;
  </code></pre>
  
  <p>Please help me make the matrix such as the one I mentioned at the top. I have no idea how to handle sparse matrix. </p>