Skip to content

zhangyilun/xgb-explainer-vis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xgb-explainer-vis

Function to visualize the XGBoost explainer in Python.

The XGBoost explainer in Python is cloned from: https://github.com/gameofdimension/xgboost_explainer and combined with my plotting code.

The function will plot the contribution of each variable to the final prediction in the order of absolute contribution.

Usage

# import
import xgboost as xgb
from xgboost_visualizer import *

# train a XGBoost model using xgb.train() rather than the sklearn equivalent interface.
xgb_trained = xgb.train(dtrain, ...)

# get a feature list for the variables used in the model training
features = [...]

# get a sample
sample = xgb.DMatrix(...)

# plot contribution
plot_contribution(xgb_trained, sample, features)

Example

The output plot will look like the following:

About

Function to visualize the XGBoost explainer in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published