{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Contributions plot\n",
"\n",
"contribution_plot is a method that displays violin or scatter plot.
\n",
"The purpose of these representations is to understand how a feature affects a prediction.
\n",
"\n",
"This tutorial presents the different parameters you can
\n",
"use in *contribution_plot* to tune output.\n",
"\n",
"Contents:\n",
"- Classification case: Specify the target modality to display.\n",
"- Sampling parameter\n",
"- Focus on a subset\n",
"- Violin or Scatter? Make your own choice\n",
"\n",
"\n",
"Data from Kaggle [Titanic](https://www.kaggle.com/c/titanic/data)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"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",
"metadata": {},
"source": [
"## Building Supervized Model "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load Titanic data"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from shapash.data.data_loader import data_loading\n",
"titanic_df, titanic_dict = data_loading('titanic')\n",
"y_df=titanic_df['Survived'].to_frame()\n",
"X_df=titanic_df[titanic_df.columns.difference(['Survived'])]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | Survived | \n", "Pclass | \n", "Name | \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", " | \n", " |
1 | \n", "0 | \n", "Third class | \n", "Braund Owen Harris | \n", "male | \n", "22.0 | \n", "1 | \n", "0 | \n", "7.25 | \n", "Southampton | \n", "Mr | \n", "
2 | \n", "1 | \n", "First class | \n", "Cumings John Bradley (Florence Briggs Thayer) | \n", "female | \n", "38.0 | \n", "1 | \n", "0 | \n", "71.28 | \n", "Cherbourg | \n", "Mrs | \n", "
3 | \n", "1 | \n", "Third class | \n", "Heikkinen Laina | \n", "female | \n", "26.0 | \n", "0 | \n", "0 | \n", "7.92 | \n", "Southampton | \n", "Miss | \n", "
4 | \n", "1 | \n", "First class | \n", "Futrelle Jacques Heath (Lily May Peel) | \n", "female | \n", "35.0 | \n", "1 | \n", "0 | \n", "53.10 | \n", "Southampton | \n", "Mrs | \n", "
5 | \n", "0 | \n", "Third class | \n", "Allen William Henry | \n", "male | \n", "35.0 | \n", "0 | \n", "0 | \n", "8.05 | \n", "Southampton | \n", "Mr | \n", "