3
$\begingroup$

I'm using an xgboost model in R to calculate the probability of the New England Patriots wining a certain game. I have variables such as opposing team, previous record against the team, current season record, team-player configuration, time of day etc.

Now, if I have probability of 40% winning against the Browns and 15% against the Green Bay Packers, how do I know which variables are influencing this probability? What is causing the 25% difference in probability?

I know xgboost.importance() gives the variable importance at the model level. But it doesn't tell me the important variables at the observation level.

Can xgboost.importance() give me the required output?

Is there another way?

Is it theoretically possible? Is it possible in xgboost - R?

PS: I'm new in the Matrix so apologize for any cardinal sins I might have committed while posting this.

$\endgroup$
2
$\begingroup$

Variable importance is useful for global interpretability of the model. What you need is local interpretability of the model. One framework for local interpretability is LIME - see https://github.com/marcotcr/lime. Good overview of intrepretability and related issues can be found in here: https://www.oreilly.com/ideas/ideas-on-interpreting-machine-learning.

$\endgroup$
1
$\begingroup$

You can use SHAP values, they are implemented in XGBoost R.

pred_contr <- predict(xgb_model, test, predcontrib = TRUE)

For the 1st record, features that had non-zero contribution to prediction:

contr1 <- pred_contr[1,]

contr1 <- contr1[-length(contr1)] # drop BIAS

contr1 <- contr1[contr1 != 0] # drop non-contributing features

contr1 <- contr1[order(abs(contr1))] # order by contribution magnitude

old_mar <- par("mar")

par(mar = old_mar + c(0,7,0,0))

barplot(contr1, horiz = TRUE, las = 2, xlab = "contribution to prediction in log-odds")

par(mar = old_mar)

$\endgroup$
1
  • $\begingroup$ Welcome to CV and thank you for your answer. Although your answer is helpful this is rather a comment than an answer. Maybe you can extend on it. $\endgroup$ – Ferdi Feb 5 '19 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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