I am currently trying to solve a binary classification problem with models. I am running into a bit of trouble with my models. I have tried a number of various ways to go about my code, including classification trees, logistic regression, as well as an xgboosted tree. All of the models have ran, and had various levels of success. My question is that I have a great xgboosted model. However, I am struggling because I have no idea how/where to go to interpret the model. I have done all of the accuracy, sensitivity, specificity, as well as created a ROC Curve already. What I am confused on is if there is a way to interpret classification tree models the same was logistic regression works where we can see independent variables and coefficients for each variable going into the model. Or is there an easier way to actually digest the tree to see what variables are impacting the model? Any advice would greatly be appreicated. If it isn't possible, would the recommendation for predicting the future be to just do a logistic regression model and try and tune it as best as possible even if it isn't as accurate as one of the more advanced tree models. I know how to run the models but I think my understanding is leading to a disconnect as to how the practical approach to use the model to predict the future of the binary result is missing somewhere
-
$\begingroup$ 0. Welcome to CV.SE. 1. Fun question (+1), there are a lot of things to do actually, please see my answer below for details. 2. I changed the title of the question to something more descriptive, feel free to amend it further. $\endgroup$– usεr11852Commented Feb 3, 2023 at 20:48
2 Answers
The obvious techniques to try in order to"see what variables are impacting the model?" are:
- PDP; Partial dependency plots - primarily used to explain overall behaviour but has extensions that work for individual predictions too (ICE) - Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Conditional Expectation by Goldstein is a good reference )
- LIME; Local interpretable model-agnostic explanations - primarily used to explain individual predictions - "Why Should I Trust You?": Explaining the Predictions of Any Classifierby Ribeiro is a good reference)
- SHAP; SHapley Additive exPlanations - primarily used to explain individual predictions but works for overall behaviour too - A Unified Approach to Interpreting Model Predictions by Lundberg & Lee is the main reference but I prefer An Efficient Explanation of Individual Classifications using Game Theory by Strumbelj & Kononenko)
If you haven't seen it already, check Molnar's Interpretable Machine Learning book. It is amazing work, has greater coverage and will start from the basics and go into more advanced techniques very nicely. It provides a more readable and to-the-point presentation of the papers mentioned above too.
ML models like XGBoost, Random Forest and etc are usually called black box models for the exact same reason you mentioned, that they don't give you an interpretable functional form like statistical models such as logistic regression. However, you can still extract variable importance out of them to get some insight on which of the predictors are more important. Alternatively, you can try partial dependence plots that are model agnostic and can explain how the dependent variable changes with the independent variables. But they are not perfect and they have their own pros and cons. For more information check out this link: https://scikit-learn.org/stable/modules/partial_dependence.html#:~:text=Partial%20dependence%20plots%20(PDP)%20show,the%20'complement'%20features.
Also, nothing stops you to create more complicated interpretable models yourself. For example, you don't have to use the vanilla logistic regression form for your problem. You can extend it by adding interactions, nonlinearity and etc to enhance its flexibility and also performance and keep the interpretability in place. For example, you can check my answer to another question for which I customize a logistic regression to be more flexible: Analyse categorial data where best outcome is middle level
-
$\begingroup$ Adding interactions absolutely does not maintain interpretability $\endgroup$– FirebugCommented Feb 3, 2023 at 18:56
-
$\begingroup$ @Firebug well I think you are absolutely wrong. For example see: cscu.cornell.edu/wp-content/uploads/84_lgsint.pdf $\endgroup$– Amin ShnCommented Feb 3, 2023 at 19:03
-
$\begingroup$ I think Firebug is a bit harsh but not wrong. If anything one should do a 2D PDP (i.e. a surface) to visualise that interaction. Strong interactions can mess up a PDP. But we have ALEs to partially alleviate that. $\endgroup$ Commented Feb 3, 2023 at 19:11
-
$\begingroup$ @usεr11852 I agree interaction between continuous variables makes things messy but I believe still you can do a lot without using a 2D surface. For example, check the effects & marginaleffects packages in R for visualising such interactions. $\endgroup$– Amin ShnCommented Feb 3, 2023 at 19:23
-
$\begingroup$ Plus having a succinct functional form is always helpful even if we struggle to visualise it. $\endgroup$– Amin ShnCommented Feb 3, 2023 at 19:32