title: Determine WHY Features Are Important in Decision Tree Models
body: <p>Often-times stakeholders don't want a black-box model that's good at predicting; they want insights about features to have a better understanding about their business, and so they can explain it to others.</p>
  
  <p>When we inspect the feature importance of an xgboost or sklearn gradient boosting model, we can determine the feature importance... but we don't understand WHY the features are important, do we?</p>
  
  <p><strong>Is there a way to explain not only what features are important but also WHY they're important?</strong></p>
  
  <p>I was told to use <a href="https://github.com/slundberg/shap" rel="noreferrer">shap</a> but running even some of the boilerplate examples throws errors so I'm looking for alternatives (or even just a procedural way to inspect trees and glean insights I can take away other than a <code>plot_importance()</code> plot).</p>
  
  <p>In the example below, how does one go about explaining WHY feature <code>f19</code> is the most important (while also realizing that decision trees are random without a random_state or seed).</p>
  
  <pre><code>from xgboost import XGBClassifier, plot_importance
  from sklearn.datasets import make_classification
  import matplotlib.pyplot as plt
  X,y = make_classification(random_state=68)
  xgb = XGBClassifier()
  xgb.fit(X, y)
  plot_importance(xgb)
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vxHJu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vxHJu.png" alt="feature_importance"></a></p>
  
  <p><strong>Update:</strong>
  What I'm looking for is a <strong>programmatic</strong> procedural proof that the features chosen by the model above contribute either positively or negatively to the predictive power. I want to see <strong>code</strong> (not theory) of how you would go about inspecting the actual model and determining each feature's positive or negative contribution. Currently, I maintain that it's not possible so somebody please prove me wrong. I'd love to be wrong!</p>
  
  <p>I also understand that decision trees are non-parametric and have no coefficients. Still, is there a way to see if a feature contributes positively (one unit of this feature increases y) or negatively (one unit of this feature decreases y).</p>
  
  <p><strong>Update2:</strong>
  Despite a thumbs down on this question, and several "close" votes, it seems this question isn't so crazy after all. <a href="http://rstudio-pubs-static.s3.amazonaws.com/283647_c3ab1ccee95a403ebe3d276599a85ab8.html" rel="noreferrer">Partial dependence plots</a> might be the answer.</p>
  
  <blockquote>
    <p>Partial Dependence Plots (PDP) were introduced by Friedman (2001) with
    purpose of interpreting complex Machine Learning algorithms.
    Interpreting a linear regression model is not as complicated as
    interpreting Support Vector Machine, Random Forest or Gradient
    Boosting Machine models, this is were Partial Dependence Plot can come
    into use. For some statistical explaination you can refer hereand More
    Advance. Some of the algorithms have methods for finding variable
    importance but they do not express whether a varaible is <strong>positively</strong> or
    <strong>negatively</strong> affecting the model .</p>
  </blockquote>