{"id":892,"date":"2022-06-10T18:09:45","date_gmt":"2022-06-10T16:09:45","guid":{"rendered":"https:\/\/lorentzen.ch\/?p=892"},"modified":"2022-06-10T18:14:07","modified_gmt":"2022-06-10T16:14:07","slug":"visualize-shap-values-without-tears","status":"publish","type":"post","link":"https:\/\/lorentzen.ch\/index.php\/2022\/06\/10\/visualize-shap-values-without-tears\/","title":{"rendered":"Visualize SHAP Values without Tears"},"content":{"rendered":"\n<p>SHAP (SHapley Additive exPlanations, Lundberg and Lee, 2017) is an ingenious way to study black box models. SHAP values decompose &#8211; as fair as possible &#8211; predictions into additive feature contributions. <\/p>\n\n\n\n<p>When it comes to SHAP, the <a href=\"https:\/\/github.com\/slundberg\/shap\">Python implementation<\/a> is the de-facto standard. It not only offers many SHAP algorithms, but also provides beautiful plots. In R, the situation is a bit more confusing. Different packages contain implementations of SHAP algorithms, e.g., <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/CRAN.R-project.org\/package=xgboost\"><code>XGBoost<\/code><\/a>,<\/li><li><a href=\"https:\/\/CRAN.R-project.org\/package=lightgbm\"><code>LightGBM<\/code><\/a>,<\/li><li><a href=\"https:\/\/CRAN.R-project.org\/package=fastshap\"><code>fastshap<\/code><\/a>, and<\/li><li><a href=\"https:\/\/github.com\/ModelOriented\/treeshap\"><code>treeshap<\/code><\/a>,<\/li><\/ul>\n\n\n\n<p>some of which with great visualizations. Plus there is SHAPforxgboost (see my <a href=\"https:\/\/lorentzen.ch\/index.php\/2021\/06\/23\/shap-analysis-in-9-lines\/\">recent post<\/a>), originally designed to visualize the results of SHAP values calculated from XGBoost, but it can also be used more generally by now.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The shapviz package<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"240\" height=\"278\" src=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/logo.png\" alt=\"\" class=\"wp-image-894\"\/><\/figure>\n\n\n\n<p>In order to entangle calculation from visualization, the <code>shapviz<\/code> package was designed. It solely focuses on visualization of SHAP values. Closely following its <a href=\"https:\/\/github.com\/mayer79\/shapviz\">README<\/a>, it currently provides these plots:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>sv_waterfall()<\/code>: Waterfall plots to study single predictions.<\/li><li><code>sv_force()<\/code>: Force plots as an alternative to waterfall plots.<\/li><li><code>sv_importance()<\/code>: Importance plots (bar and\/or beeswarm plots) to study variable importance.<\/li><li><code>sv_dependence()<\/code>: Dependence plots to study feature effects (optionally colored by heuristically strongest interacting feature).<\/li><\/ul>\n\n\n\n<p>They require a&nbsp;&#8220;<code>shapviz<\/code>&#8221; object, which is built from two things only:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><code>S<\/code>: Matrix of SHAP values<\/li><li><code>X<\/code>: Dataset with corresponding feature values<\/li><\/ol>\n\n\n\n<p>Furthermore, a&nbsp;&#8220;<code>baseline<\/code>&#8221;&nbsp;can be passed to represent an average prediction on the scale of the SHAP values.<\/p>\n\n\n\n<p>A key feature of the&nbsp;&#8220;<code>shapviz<\/code>&#8221;&nbsp;package is that&nbsp;<code>X<\/code>&nbsp;is used for visualization only. <em>Thus it is perfectly fine to use factor variables, even if the underlying model would not accept these.<\/em><\/p>\n\n\n\n<p>To further simplify the use of&nbsp;<code>shapviz<\/code>, direct connectors to the packages<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/cran.r-project.org\/package=xgboost\"><code>XGBoost<\/code><\/a>,<\/li><li><a href=\"https:\/\/cran.r-project.org\/package=lightgbm\"><code>LightGBM<\/code><\/a>,<\/li><li><a href=\"https:\/\/cran.r-project.org\/package=fastshap\"><code>fastshap<\/code><\/a>, and<\/li><li><a href=\"https:\/\/github.com\/ModelOriented\/treeshap\"><code>treeshap<\/code><\/a><\/li><\/ul>\n\n\n\n<p>are available.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installation<\/h3>\n\n\n\n<p>The package <code>shapviz<\/code> can be installed from CRAN or Github:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>devtools::install_github(\"shapviz\")<\/code><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><code>devtools::install_github(\"mayer79\/shapviz\")<\/code><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<p>Shiny diamonds&#8230; let&#8217;s model their prices by four &#8220;c&#8221; variables with XGBoost, and create an explanation dataset with 2000 randomly picked diamonds.<\/p>\n\n\n<div class=\"wp-block-ub-tabbed-content wp-block-ub-tabbed-content-holder wp-block-ub-tabbed-content-horizontal-holder-mobile wp-block-ub-tabbed-content-horizontal-holder-tablet\" id=\"ub-tabbed-content-ce51075e-903d-4fc8-9f4c-2ca75a0e14de\" style=\"\">\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-holder horizontal-tab-width-mobile horizontal-tab-width-tablet\">\n\t\t\t\t<div role=\"tablist\" class=\"wp-block-ub-tabbed-content-tabs-title wp-block-ub-tabbed-content-tabs-title-mobile-horizontal-tab wp-block-ub-tabbed-content-tabs-title-tablet-horizontal-tab\" style=\"justify-content: flex-start; \"><div role=\"tab\" id=\"ub-tabbed-content-ce51075e-903d-4fc8-9f4c-2ca75a0e14de-tab-0\" aria-controls=\"ub-tabbed-content-ce51075e-903d-4fc8-9f4c-2ca75a0e14de-panel-0\" aria-selected=\"true\" class=\"wp-block-ub-tabbed-content-tab-title-wrap active\" style=\"--ub-tabbed-title-background-color: #6d6d6d; --ub-tabbed-active-title-color: inherit; --ub-tabbed-active-title-background-color: #6d6d6d; text-align: center; \" tabindex=\"-1\">\n\t\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-title\">R<\/div>\n\t\t\t<\/div><\/div>\n\t\t\t<\/div>\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tabs-content\" style=\"\"><div role=\"tabpanel\" class=\"wp-block-ub-tabbed-content-tab-content-wrap active\" id=\"ub-tabbed-content-ce51075e-903d-4fc8-9f4c-2ca75a0e14de-panel-0\" aria-labelledby=\"ub-tabbed-content-ce51075e-903d-4fc8-9f4c-2ca75a0e14de-tab-0\" tabindex=\"0\">\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting='{\"showPanel\":true,\"languageLabel\":\"language\",\"fullScreenButton\":true,\"copyButton\":true,\"mode\":\"r\",\"mime\":\"text\/x-rsrc\",\"theme\":\"material\",\"lineNumbers\":false,\"styleActiveLine\":false,\"lineWrapping\":false,\"readOnly\":true,\"fileName\":\"\",\"language\":\"R\",\"maxHeight\":\"400px\",\"modeName\":\"r\"}'>library(shapviz)\nlibrary(ggplot2)\nlibrary(xgboost)\n\nset.seed(3653)\n\nX &lt;- diamonds[c(\"carat\", \"cut\", \"color\", \"clarity\")]\ndtrain &lt;- xgb.DMatrix(data.matrix(X), label = diamonds$price)\n\nfit &lt;- xgb.train(\n  params = list(learning_rate = 0.1, objective = \"reg:squarederror\"), \n  data = dtrain,\n  nrounds = 65L\n)\n\n# Explanation dataset\nX_small &lt;- X[sample(nrow(X), 2000L), ]<\/pre><\/div>\n\n<\/div><\/div>\n\t\t<\/div>\n\n\n<h4 class=\"wp-block-heading\">Create &#8220;shapviz&#8221; object<\/h4>\n\n\n\n<p>One line of code creates a&nbsp;<code>shapviz<\/code>&nbsp;object. It contains SHAP values and feature values for the set of observations we are interested in. Note again that&nbsp;<code>X<\/code>&nbsp;is solely used as explanation dataset, not for calculating SHAP values.<\/p>\n\n\n\n<p>In this example we construct the&nbsp;<code>shapviz<\/code>&nbsp;object directly from the fitted XGBoost model. Thus we also need to pass a corresponding prediction dataset&nbsp;<code>X_pred<\/code>&nbsp;used for calculating SHAP values by XGBoost.<\/p>\n\n\n<div class=\"wp-block-ub-tabbed-content wp-block-ub-tabbed-content-holder wp-block-ub-tabbed-content-horizontal-holder-mobile wp-block-ub-tabbed-content-horizontal-holder-tablet\" id=\"ub-tabbed-content-fa4c1cc1-bbac-427a-a633-1408dc3593ba\" style=\"\">\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-holder horizontal-tab-width-mobile horizontal-tab-width-tablet\">\n\t\t\t\t<div role=\"tablist\" class=\"wp-block-ub-tabbed-content-tabs-title wp-block-ub-tabbed-content-tabs-title-mobile-horizontal-tab wp-block-ub-tabbed-content-tabs-title-tablet-horizontal-tab\" style=\"justify-content: flex-start; \"><div role=\"tab\" id=\"ub-tabbed-content-fa4c1cc1-bbac-427a-a633-1408dc3593ba-tab-0\" aria-controls=\"ub-tabbed-content-fa4c1cc1-bbac-427a-a633-1408dc3593ba-panel-0\" aria-selected=\"true\" class=\"wp-block-ub-tabbed-content-tab-title-wrap active\" style=\"--ub-tabbed-title-background-color: #6d6d6d; --ub-tabbed-active-title-color: inherit; --ub-tabbed-active-title-background-color: #6d6d6d; text-align: center; \" tabindex=\"-1\">\n\t\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-title\">R<\/div>\n\t\t\t<\/div><\/div>\n\t\t\t<\/div>\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tabs-content\" style=\"\"><div role=\"tabpanel\" class=\"wp-block-ub-tabbed-content-tab-content-wrap active\" id=\"ub-tabbed-content-fa4c1cc1-bbac-427a-a633-1408dc3593ba-panel-0\" aria-labelledby=\"ub-tabbed-content-fa4c1cc1-bbac-427a-a633-1408dc3593ba-tab-0\" tabindex=\"0\">\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting='{\"showPanel\":true,\"languageLabel\":\"language\",\"fullScreenButton\":true,\"copyButton\":true,\"mode\":\"r\",\"mime\":\"text\/x-rsrc\",\"theme\":\"material\",\"lineNumbers\":false,\"styleActiveLine\":false,\"lineWrapping\":false,\"readOnly\":true,\"fileName\":\"\",\"language\":\"R\",\"maxHeight\":\"400px\",\"modeName\":\"r\"}'>shp &lt;- shapviz(fit, X_pred = data.matrix(X_small), X = X_small)<\/pre><\/div>\n\n<\/div><\/div>\n\t\t<\/div>\n\n\n<h4 class=\"wp-block-heading\">Explaining one single prediction<\/h4>\n\n\n\n<p>Let&#8217;s start by explaining a single prediction by a waterfall plot or, alternatively, a force plot. <\/p>\n\n\n<div class=\"wp-block-ub-tabbed-content wp-block-ub-tabbed-content-holder wp-block-ub-tabbed-content-horizontal-holder-mobile wp-block-ub-tabbed-content-horizontal-holder-tablet\" id=\"ub-tabbed-content-65483ed8-d1ac-4dd0-b284-b0abbaa2cde8\" style=\"\">\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-holder horizontal-tab-width-mobile horizontal-tab-width-tablet\">\n\t\t\t\t<div role=\"tablist\" class=\"wp-block-ub-tabbed-content-tabs-title wp-block-ub-tabbed-content-tabs-title-mobile-horizontal-tab wp-block-ub-tabbed-content-tabs-title-tablet-horizontal-tab\" style=\"justify-content: flex-start; \"><div role=\"tab\" id=\"ub-tabbed-content-65483ed8-d1ac-4dd0-b284-b0abbaa2cde8-tab-0\" aria-controls=\"ub-tabbed-content-65483ed8-d1ac-4dd0-b284-b0abbaa2cde8-panel-0\" aria-selected=\"true\" class=\"wp-block-ub-tabbed-content-tab-title-wrap active\" style=\"--ub-tabbed-title-background-color: #6d6d6d; --ub-tabbed-active-title-color: inherit; --ub-tabbed-active-title-background-color: #6d6d6d; text-align: center; \" tabindex=\"-1\">\n\t\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-title\">R<\/div>\n\t\t\t<\/div><\/div>\n\t\t\t<\/div>\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tabs-content\" style=\"\"><div role=\"tabpanel\" class=\"wp-block-ub-tabbed-content-tab-content-wrap active\" id=\"ub-tabbed-content-65483ed8-d1ac-4dd0-b284-b0abbaa2cde8-panel-0\" aria-labelledby=\"ub-tabbed-content-65483ed8-d1ac-4dd0-b284-b0abbaa2cde8-tab-0\" tabindex=\"0\">\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting='{\"showPanel\":true,\"languageLabel\":\"language\",\"fullScreenButton\":true,\"copyButton\":true,\"mode\":\"r\",\"mime\":\"text\/x-rsrc\",\"theme\":\"material\",\"lineNumbers\":false,\"styleActiveLine\":false,\"lineWrapping\":false,\"readOnly\":true,\"fileName\":\"\",\"language\":\"R\",\"maxHeight\":\"400px\",\"modeName\":\"r\"}'># Two types of visualizations\nsv_waterfall(shp, row_id = 1)\nsv_force(shp, row_id = 1<\/pre><\/div>\n\n<\/div><\/div>\n\t\t<\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"563\" height=\"375\" src=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-waterfall.jpg\" alt=\"\" class=\"wp-image-901\" srcset=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-waterfall.jpg 563w, https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-waterfall-300x200.jpg 300w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><figcaption>Waterfall plot<\/figcaption><\/figure>\n\n\n\n<p>Factor\/character variables are kept as they are, even if the underlying XGBoost model required them to be integer encoded.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"563\" height=\"186\" src=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-force.jpg\" alt=\"\" class=\"wp-image-902\" srcset=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-force.jpg 563w, https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-force-300x99.jpg 300w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><figcaption>Force plot<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Explaining the model as a whole<\/h4>\n\n\n\n<p>We have decomposed 2000 predictions, not just one. This allows us to study <strong>variable importance<\/strong> at a global model level by studying average absolute SHAP values as a bar plot or by looking at beeswarm plots of SHAP values.<\/p>\n\n\n<div class=\"wp-block-ub-tabbed-content wp-block-ub-tabbed-content-holder wp-block-ub-tabbed-content-horizontal-holder-mobile wp-block-ub-tabbed-content-horizontal-holder-tablet\" id=\"ub-tabbed-content-a0bb489e-fad4-41c2-8aed-0cbe6f515a62\" style=\"\">\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-holder horizontal-tab-width-mobile horizontal-tab-width-tablet\">\n\t\t\t\t<div role=\"tablist\" class=\"wp-block-ub-tabbed-content-tabs-title wp-block-ub-tabbed-content-tabs-title-mobile-horizontal-tab wp-block-ub-tabbed-content-tabs-title-tablet-horizontal-tab\" style=\"justify-content: flex-start; \"><div role=\"tab\" id=\"ub-tabbed-content-a0bb489e-fad4-41c2-8aed-0cbe6f515a62-tab-0\" aria-controls=\"ub-tabbed-content-a0bb489e-fad4-41c2-8aed-0cbe6f515a62-panel-0\" aria-selected=\"true\" class=\"wp-block-ub-tabbed-content-tab-title-wrap active\" style=\"--ub-tabbed-title-background-color: #6d6d6d; --ub-tabbed-active-title-color: inherit; --ub-tabbed-active-title-background-color: #6d6d6d; text-align: center; \" tabindex=\"-1\">\n\t\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-title\">R<\/div>\n\t\t\t<\/div><\/div>\n\t\t\t<\/div>\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tabs-content\" style=\"\"><div role=\"tabpanel\" class=\"wp-block-ub-tabbed-content-tab-content-wrap active\" id=\"ub-tabbed-content-a0bb489e-fad4-41c2-8aed-0cbe6f515a62-panel-0\" aria-labelledby=\"ub-tabbed-content-a0bb489e-fad4-41c2-8aed-0cbe6f515a62-tab-0\" tabindex=\"0\">\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting='{\"showPanel\":true,\"languageLabel\":\"language\",\"fullScreenButton\":true,\"copyButton\":true,\"mode\":\"r\",\"mime\":\"text\/x-rsrc\",\"theme\":\"material\",\"lineNumbers\":false,\"styleActiveLine\":false,\"lineWrapping\":false,\"readOnly\":true,\"fileName\":\"\",\"language\":\"R\",\"maxHeight\":\"400px\",\"modeName\":\"r\"}'># Three types of variable importance plots\nsv_importance(shp)\nsv_importance(shp, kind = \"bar\")\nsv_importance(shp, kind = \"both\", alpha = 0.2, width = 0.2)<\/pre><\/div>\n\n<\/div><\/div>\n\t\t<\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"400\" src=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp1.png\" alt=\"\" class=\"wp-image-903\" srcset=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp1.png 600w, https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp1-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption>Beeswarm plot<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"563\" height=\"375\" src=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp2.jpg\" alt=\"\" class=\"wp-image-905\" srcset=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp2.jpg 563w, https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp2-300x200.jpg 300w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><figcaption>Bar plot<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"400\" src=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp3.png\" alt=\"\" class=\"wp-image-904\" srcset=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp3.png 600w, https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-imp3-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption>Beeswarm plot overlaid with bar plot<\/figcaption><\/figure>\n\n\n\n<p>A scatterplot of SHAP values of a feature like&nbsp;<code>color<\/code>&nbsp;against its observed values gives a great impression on the <strong>feature effect<\/strong> on the response. Vertical scatter gives additional info on interaction effects.&nbsp;<code>shapviz<\/code>&nbsp;offers a heuristic to pick another feature on the color scale with potential strongest interaction.<\/p>\n\n\n<div class=\"wp-block-ub-tabbed-content wp-block-ub-tabbed-content-holder wp-block-ub-tabbed-content-horizontal-holder-mobile wp-block-ub-tabbed-content-horizontal-holder-tablet\" id=\"ub-tabbed-content-42994091-8615-4e85-91ca-f13ba5fec6f2\" style=\"\">\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-holder horizontal-tab-width-mobile horizontal-tab-width-tablet\">\n\t\t\t\t<div role=\"tablist\" class=\"wp-block-ub-tabbed-content-tabs-title wp-block-ub-tabbed-content-tabs-title-mobile-horizontal-tab wp-block-ub-tabbed-content-tabs-title-tablet-horizontal-tab\" style=\"justify-content: flex-start; \"><div role=\"tab\" id=\"ub-tabbed-content-42994091-8615-4e85-91ca-f13ba5fec6f2-tab-0\" aria-controls=\"ub-tabbed-content-42994091-8615-4e85-91ca-f13ba5fec6f2-panel-0\" aria-selected=\"true\" class=\"wp-block-ub-tabbed-content-tab-title-wrap active\" style=\"--ub-tabbed-title-background-color: #6d6d6d; --ub-tabbed-active-title-color: inherit; --ub-tabbed-active-title-background-color: #6d6d6d; text-align: center; \" tabindex=\"-1\">\n\t\t\t\t<div class=\"wp-block-ub-tabbed-content-tab-title\">R<\/div>\n\t\t\t<\/div><\/div>\n\t\t\t<\/div>\n\t\t\t<div class=\"wp-block-ub-tabbed-content-tabs-content\" style=\"\"><div role=\"tabpanel\" class=\"wp-block-ub-tabbed-content-tab-content-wrap active\" id=\"ub-tabbed-content-42994091-8615-4e85-91ca-f13ba5fec6f2-panel-0\" aria-labelledby=\"ub-tabbed-content-42994091-8615-4e85-91ca-f13ba5fec6f2-tab-0\" tabindex=\"0\">\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting='{\"showPanel\":true,\"languageLabel\":\"language\",\"fullScreenButton\":true,\"copyButton\":true,\"mode\":\"r\",\"mime\":\"text\/x-rsrc\",\"theme\":\"material\",\"lineNumbers\":false,\"styleActiveLine\":false,\"lineWrapping\":false,\"readOnly\":true,\"fileName\":\"\",\"language\":\"R\",\"maxHeight\":\"400px\",\"modeName\":\"r\"}'>sv_dependence(shp, v = \"color\", \"auto\")<\/pre><\/div>\n\n<\/div><\/div>\n\t\t<\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"400\" src=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-dep.png\" alt=\"\" class=\"wp-image-906\" srcset=\"https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-dep.png 600w, https:\/\/lorentzen.ch\/wp-content\/uploads\/2022\/06\/README-dep-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption>Dependence plot with automatic interaction colorization<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>The &#8220;shapviz&#8221; has a single purpose: making SHAP plots.<\/li><li>Its interface is optimized for existing SHAP crunching packages and can easily be used in future packages as well.<\/li><li>All plots are highly customizable. Furthermore, they are all written with <code>ggplot<\/code> and allow corresponding modifications.<\/li><\/ul>\n\n\n\n<p>The complete R script can be found <a href=\"https:\/\/github.com\/lorentzenchr\/notebooks\/blob\/master\/blogposts\/2022-06-10%20shapviz.R\">here<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">References<\/h3>\n\n\n\n<p>Scott M. Lundberg and Su-In Lee. A Unified Approach to Interpreting Model Predictions. Advances in Neural Information Processing Systems 30 (2017).<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visualize SHAP values without tears.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,17,9],"tags":[5],"class_list":["post-892","post","type-post","status-publish","format-standard","hentry","category-machine-learning","category-programming","category-statistics","tag-r"],"featured_image_src":null,"author_info":{"display_name":"Michael Mayer","author_link":"https:\/\/lorentzen.ch\/index.php\/author\/michael\/"},"_links":{"self":[{"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/posts\/892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/comments?post=892"}],"version-history":[{"count":15,"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/posts\/892\/revisions"}],"predecessor-version":[{"id":916,"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/posts\/892\/revisions\/916"}],"wp:attachment":[{"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/media?parent=892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/categories?post=892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lorentzen.ch\/index.php\/wp-json\/wp\/v2\/tags?post=892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}