This function plots SHAP Interaction value for two variables depending on the value of the first variable. Value of the second variable is marked with the color.

plot_interaction(
  treeshap,
  var1,
  var2,
  title = "SHAP Interaction Value Plot",
  subtitle = ""
)

Arguments

treeshap

A treeshap object produced with treeshap(interactions = TRUE) function. treeshap.object.

var1

name or index of the first variable - plotted on x axis.

var2

name or index of the second variable - marked with color.

title

the plot's title, by default 'SHAP Interaction Value Plot'.

subtitle

the plot's subtitle. By default no subtitle.

Value

a ggplot2 object

See also

treeshap for calculation of SHAP Interaction values

plot_contribution, plot_feature_importance, plot_feature_dependence

Examples

# \donttest{
data <- fifa20$data[colnames(fifa20$data) != 'work_rate']
target <- fifa20$target
param2 <- list(objective = "reg:squarederror", max_depth = 5)
xgb_model2 <- xgboost::xgboost(as.matrix(data), params = param2, label = target, nrounds = 10)
#> [1]	train-rmse:4410502.640602 
#> [2]	train-rmse:3204455.983007 
#> [3]	train-rmse:2357567.731600 
#> [4]	train-rmse:1761437.051456 
#> [5]	train-rmse:1348371.142976 
#> [6]	train-rmse:1060255.788303 
#> [7]	train-rmse:864380.163679 
#> [8]	train-rmse:739236.388283 
#> [9]	train-rmse:652447.890717 
#> [10]	train-rmse:593169.488405 
unified_model2 <- xgboost.unify(xgb_model2, data)
inters <- treeshap(unified_model2, as.matrix(data[1:50, ]), interactions = TRUE)
#> 
|0%----|------|20%---|------|40%---|------|60%---|------|80%---|------|100%
#> =---------------------------------------------------------------------- (0%)

==--------------------------------------------------------------------- (2%)

===-------------------------------------------------------------------- (4%)

=====------------------------------------------------------------------ (6%)

======----------------------------------------------------------------- (8%)

========--------------------------------------------------------------- (10%)

=========-------------------------------------------------------------- (12%)

==========------------------------------------------------------------- (14%)

============----------------------------------------------------------- (16%)

=============---------------------------------------------------------- (18%)

===============-------------------------------------------------------- (20%)

================------------------------------------------------------- (22%)

=================------------------------------------------------------ (24%)

===================---------------------------------------------------- (26%)

====================--------------------------------------------------- (28%)

======================------------------------------------------------- (30%)

=======================------------------------------------------------ (32%)

========================----------------------------------------------- (34%)

==========================--------------------------------------------- (36%)

===========================-------------------------------------------- (38%)

=============================------------------------------------------ (40%)

==============================----------------------------------------- (42%)

===============================---------------------------------------- (44%)

=================================-------------------------------------- (46%)

==================================------------------------------------- (48%)

====================================----------------------------------- (50%)

=====================================---------------------------------- (52%)

======================================--------------------------------- (54%)

========================================------------------------------- (56%)

=========================================------------------------------ (58%)

===========================================---------------------------- (60%)

============================================--------------------------- (62%)

=============================================-------------------------- (64%)

===============================================------------------------ (66%)

================================================----------------------- (68%)

==================================================--------------------- (70%)

===================================================-------------------- (72%)

====================================================------------------- (74%)

======================================================----------------- (76%)

=======================================================---------------- (78%)

=========================================================-------------- (80%)

==========================================================------------- (82%)

===========================================================------------ (84%)

=============================================================---------- (86%)

==============================================================--------- (88%)

================================================================------- (90%)

=================================================================------ (92%)

==================================================================----- (94%)

====================================================================--- (96%)

=====================================================================-- (98%)

======================================================================= (100%)

plot_interaction(inters, "dribbling", "defending")
#> Warning: Removed 9 rows containing missing values (`geom_point()`).

# }