{ "cells": [ { "cell_type": "markdown", "id": "continued-hamburg", "metadata": {}, "source": [ "# Interactions plot\n", "\n", "Most explainability plots only allow the user to analyze one variable at a time. \n", "\n", "**Interactions plots are an interesting way to visualize a couple of variables and their corresponding contribution to the model output.**\n", "\n", "Shapash integrates two methods that allow to display such interactions for several individuals : `interactions_plot` and `top_interactions_plot`.\n", "\n", "This tutorial presents how to use both methods to get more insights about your model and how two variables interact with it.\n", "\n", "Content :\n", "- Loading dataset and fitting a model\n", "- Declare and compile Shapash smart explainer\n", "- Plot top interaction values\n", "- Plot a chosen couple of variables\n", "\n", "We used Kaggle's [Titanic](https://www.kaggle.com/c/titanic/data) dataset" ] }, { "cell_type": "code", "execution_count": 1, "id": "oriented-jewelry", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from category_encoders import OrdinalEncoder\n", "from xgboost import XGBClassifier\n", "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "markdown", "id": "enclosed-hartford", "metadata": {}, "source": [ "## Building Supervized Model \n", "Load Titanic data" ] }, { "cell_type": "code", "execution_count": 3, "id": "compressed-jimmy", "metadata": {}, "outputs": [], "source": [ "from shapash.data.data_loader import data_loading\n", "titanic_df, titanic_dict = data_loading('titanic')\n", "del titanic_df['Name']\n", "y_df=titanic_df['Survived']\n", "X_df=titanic_df[titanic_df.columns.difference(['Survived'])]" ] }, { "cell_type": "code", "execution_count": 4, "id": "interpreted-protein", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Survived | \n", "Pclass | \n", "Sex | \n", "Age | \n", "SibSp | \n", "Parch | \n", "Fare | \n", "Embarked | \n", "Title | \n", "
---|---|---|---|---|---|---|---|---|---|
PassengerId | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
1 | \n", "0 | \n", "Third class | \n", "male | \n", "22.0 | \n", "1 | \n", "0 | \n", "7.25 | \n", "Southampton | \n", "Mr | \n", "
2 | \n", "1 | \n", "First class | \n", "female | \n", "38.0 | \n", "1 | \n", "0 | \n", "71.28 | \n", "Cherbourg | \n", "Mrs | \n", "
3 | \n", "1 | \n", "Third class | \n", "female | \n", "26.0 | \n", "0 | \n", "0 | \n", "7.92 | \n", "Southampton | \n", "Miss | \n", "
4 | \n", "1 | \n", "First class | \n", "female | \n", "35.0 | \n", "1 | \n", "0 | \n", "53.10 | \n", "Southampton | \n", "Mrs | \n", "
5 | \n", "0 | \n", "Third class | \n", "male | \n", "35.0 | \n", "0 | \n", "0 | \n", "8.05 | \n", "Southampton | \n", "Mr | \n", "