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 = ""
)A treeshap object produced with treeshap(interactions = TRUE) function. treeshap.object.
name or index of the first variable - plotted on x axis.
name or index of the second variable - marked with color.
the plot's title, by default 'SHAP Interaction Value Plot'.
the plot's subtitle. By default no subtitle.
a ggplot2 object
treeshap for calculation of SHAP Interaction values
plot_contribution, plot_feature_importance, plot_feature_dependence
# \donttest{
if (requireNamespace("xgboost", quietly = TRUE) &&
requireNamespace("scales", quietly = TRUE)) {
data <- fifa20$data[colnames(fifa20$data) != 'work_rate']
target <- fifa20$target
xgb_model2 <- xgboost::xgboost(
x = as.matrix(data),
y = target,
objective = "reg:squarederror",
max_depth = 5,
nrounds = 10
)
unified_model2 <- xgboost.unify(xgb_model2, data)
inters <- treeshap(unified_model2, as.matrix(data[1:50, ]), interactions = TRUE)
plot_interaction(inters, "dribbling", "defending")
}# }
#>
|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%)
#> Warning: Removed 9 rows containing missing values or values outside the scale range
#> (`geom_point()`).