.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/matplotlib/plot_main30_sepsis_shap_boxplot.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_matplotlib_plot_main30_sepsis_shap_boxplot.py: 30. Sample shap.csv boxplot --------------------------------- The aim is to visualise all the features for all the timesteps to quickly see which shap values are higher and therefore influence more in the result. .. note:: Using plotly we could interact with the outcome! .. GENERATED FROM PYTHON SOURCE LINES 12-118 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_examples/matplotlib/images/sphx_glr_plot_main30_sepsis_shap_boxplot_001.png :alt: plot main30 sepsis shap boxplot :srcset: /_examples/matplotlib/images/sphx_glr_plot_main30_sepsis_shap_boxplot_001.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/matplotlib/images/sphx_glr_plot_main30_sepsis_shap_boxplot_002.png :alt: plot main30 sepsis shap boxplot :srcset: /_examples/matplotlib/images/sphx_glr_plot_main30_sepsis_shap_boxplot_002.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/matplotlib/images/sphx_glr_plot_main30_sepsis_shap_boxplot_003.png :alt: plot main30 sepsis shap boxplot :srcset: /_examples/matplotlib/images/sphx_glr_plot_main30_sepsis_shap_boxplot_003.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Unnamed: 0 sample timestep features feature_values shap_values 0 0 0 0 Ward Lactate 0.0 0.000652 4 4 0 0 Platelets 0.0 -0.001705 5 5 0 0 Haemoglobin 0.0 -0.000918 6 6 0 0 Mean cell volume, blood 0.0 -0.000654 7 7 0 0 Haematocrit 0.0 -0.000487 16 16 0 0 Neutrophils 0.0 0.002521 17 17 0 0 Chloride 0.0 -0.000858 18 18 0 0 Lymphocytes 0.0 -0.002920 19 19 0 0 Monocytes 0.0 -0.002224 20 20 0 0 Eosinophils 0.0 -0.005246 | .. code-block:: default :lineno-start: 13 # Libraries import seaborn as sns import pandas as pd import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from scipy import stats from matplotlib.colors import LogNorm sns.set_theme(style="white") # See https://matplotlib.org/devdocs/users/explain/customizing.html mpl.rcParams['axes.titlesize'] = 8 mpl.rcParams['axes.labelsize'] = 8 mpl.rcParams['xtick.labelsize'] = 8 mpl.rcParams['ytick.labelsize'] = 8 mpl.rcParams['legend.fontsize'] = 7 mpl.rcParams['legend.handlelength'] = 1 mpl.rcParams['legend.handleheight'] = 1 mpl.rcParams['legend.loc'] = 'upper left' # Features features = [ 'Ward Lactate', #'Ward Glucose', #'Ward sO2', #'White blood cell count, blood', 'Platelets', 'Haemoglobin', 'Mean cell volume, blood', 'Haematocrit', #'Mean cell haemoglobin conc, blood', #'Mean cell haemoglobin level, blood', #'Red blood cell count, blood', #'Red blood cell distribution width', #'Creatinine', #'Urea level, blood', #'Potassium', #'Sodium', 'Neutrophils', 'Chloride', 'Lymphocytes', 'Monocytes', 'Eosinophils', 'C-Reactive Protein', 'Albumin', #'Alkaline Phosphatase', #'Glucose POCT Strip Blood', 'Total Protein', 'Globulin', 'Alanine Transaminase', 'Bilirubin', 'Prothrombin time', 'Fibrinogen (clauss)', 'Procalcitonin', 'Ferritin', 'D-Dimer', 'sex', 'age' ] # Load data data = pd.read_csv('../../datasets/shap/shap.csv') # Filter data = data[data.features.isin(features)] # Show print(data.head(10)) # .. todo:: Change flier size, cmap, ... def configure_ax(ax): sns.despine(ax=ax) lg = ax.legend(loc='upper center', bbox_to_anchor=(0.05, 1.15, 0.9, 0.1), borderaxespad=2, ncol=5, mode='expand') plt.tight_layout() # Boxenplot plt.figure(figsize=(12, 4)) ax = sns.boxenplot(data, x='timestep', y='shap_values', hue='features', saturation=0.5, showfliers=False) configure_ax(ax) # Violinplot plt.figure(figsize=(12, 4)) ax = sns.violinplot(data, x='timestep', y='shap_values', hue='features', saturation=0.5, showfliers=False, whis=1.0) configure_ax(ax) # Boxplot plt.figure(figsize=(12, 4)) ax = sns.boxplot(data, x='timestep', y='shap_values', hue='features', saturation=0.5, showfliers=False, whis=1.0) configure_ax(ax) # Show plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 4.962 seconds) .. _sphx_glr_download__examples_matplotlib_plot_main30_sepsis_shap_boxplot.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_main30_sepsis_shap_boxplot.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_main30_sepsis_shap_boxplot.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_