.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/interpretability.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_interpretability.py: Model interpretability with TabICL ============================ TabICL comes with a fast approximations of SHAP values. It is much faster than using black-box shape routines on TabICL which is slow. Here we demo it on dataset on wages .. GENERATED FROM PYTHON SOURCE LINES 12-14 The dataset: wages --------------------- .. GENERATED FROM PYTHON SOURCE LINES 14-21 .. code-block:: Python from sklearn.datasets import fetch_openml survey = fetch_openml(data_id=534, as_frame=True) X = survey.data[survey.feature_names] .. GENERATED FROM PYTHON SOURCE LINES 22-23 A quick glance at the data with skrub's TableReport .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: Python import skrub skrub.TableReport(X) .. raw:: html

Please enable javascript

The skrub table reports need javascript to display correctly. If you are displaying a report in a Jupyter notebook and you see this message, you may need to re-execute the cell or to trust the notebook (button on the top right or "File > Trust notebook").



.. GENERATED FROM PYTHON SOURCE LINES 28-29 We need to convert the categorical features to numeric ones. We can do this with pandas' get_dummies .. GENERATED FROM PYTHON SOURCE LINES 29-33 .. code-block:: Python import pandas as pd X = pd.get_dummies(X, drop_first=True) .. GENERATED FROM PYTHON SOURCE LINES 34-35 The values to predict: wages .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python y = survey.target.values.ravel() .. GENERATED FROM PYTHON SOURCE LINES 38-39 Split out a test set .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y) .. GENERATED FROM PYTHON SOURCE LINES 44-47 Our TabICL model ------------------ .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: Python from tabicl import TabICLRegressor clf = TabICLRegressor(n_estimators=4, device="cpu") clf.fit(X_train, y_train) .. rst-class:: sphx-glr-script-out .. code-block:: none Checkpoint 'tabicl-regressor-v2-20260212.ckpt' not cached. Downloading from Hugging Face Hub (jingang/TabICL). Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads. .. raw:: html
TabICLRegressor(device='cpu', n_estimators=4)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 53-60 Shap-like interpretability --------------------------- Use TabICL's fast approximations of shap-like values and plot them This part of the example requires to install the shap extra: pip install 'tabicl[shap] .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: Python from tabicl.shap import get_shap_values, plot_shap # Compute the shap values sv = get_shap_values(clf, X_test[:10]) .. rst-class:: sphx-glr-script-out .. code-block:: none PermutationExplainer explainer: 10%|█ | 1/10 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: interpretability.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: interpretability.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_