{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Postprocessing parameter in compile method\n", "\n", "Compile method is a method that creates the explainer you need for your model.
This compile method has many parameters, and among those is `postprocessing` parameter, that will be explained in this tutorial.
\n", "This parameter allows to **modify** the dataset with several techniques, for a better visualization.\n", "This tutorial presents the different way you can modify data, and the right syntax to do it.\n", "\n", "Contents:\n", "- Loading dataset and fitting a model.\n", "\n", "- Creating our SmartExplainer and compiling it without postprocessing.\n", "\n", "- New SmartExplainer with postprocessing parameter.\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 sklearn.model_selection import train_test_split\n", "from sklearn.ensemble import RandomForestClassifier" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Building Supervized Model " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### First step : Importing our dataset" ] }, { "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']\n", "X_df=titanic_df[titanic_df.columns.difference(['Survived'])]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SurvivedPclassNameSexAgeSibSpParchFareEmbarkedTitle
PassengerId
10Third classBraund Owen Harrismale22.0107.25SouthamptonMr
21First classCumings John Bradley (Florence Briggs Thayer)female38.01071.28CherbourgMrs
31Third classHeikkinen Lainafemale26.0007.92SouthamptonMiss
41First classFutrelle Jacques Heath (Lily May Peel)female35.01053.10SouthamptonMrs
50Third classAllen William Henrymale35.0008.05SouthamptonMr
\n", "
" ], "text/plain": [ " Survived Pclass \\\n", "PassengerId \n", "1 0 Third class \n", "2 1 First class \n", "3 1 Third class \n", "4 1 First class \n", "5 0 Third class \n", "\n", " Name Sex Age \\\n", "PassengerId \n", "1 Braund Owen Harris male 22.0 \n", "2 Cumings John Bradley (Florence Briggs Thayer) female 38.0 \n", "3 Heikkinen Laina female 26.0 \n", "4 Futrelle Jacques Heath (Lily May Peel) female 35.0 \n", "5 Allen William Henry male 35.0 \n", "\n", " SibSp Parch Fare Embarked Title \n", "PassengerId \n", "1 1 0 7.25 Southampton Mr \n", "2 1 0 71.28 Cherbourg Mrs \n", "3 0 0 7.92 Southampton Miss \n", "4 1 0 53.10 Southampton Mrs \n", "5 0 0 8.05 Southampton Mr " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "titanic_df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Second step : Encode our categorical variables" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from category_encoders import OrdinalEncoder\n", "\n", "categorical_features = [col for col in X_df.columns if X_df[col].dtype == 'object']\n", "\n", "encoder = OrdinalEncoder(\n", " cols=categorical_features,\n", " handle_unknown='ignore',\n", " return_df=True).fit(X_df)\n", "\n", "X_df = encoder.transform(X_df)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Third step : Train/test split and fitting our model" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "Xtrain, Xtest, ytrain, ytest = train_test_split(X_df, y_df, train_size=0.75, random_state=1)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "classifier = RandomForestClassifier(n_estimators=200).fit(Xtrain, ytrain)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "y_pred = pd.DataFrame(classifier.predict(Xtest), columns=['pred'], index=Xtest.index) # Predictions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Fourth step : Declaring our Explainer" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from shapash import SmartExplainer" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "xpl = SmartExplainer(\n", " model=classifier,\n", " preprocessing=encoder, # Optional: compile step can use inverse_transform method\n", " features_dict=titanic_dict # Optional parameter, dict specifies label for features name \n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Compiling without postprocessing parameter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After declaring our explainer, we need to compile it on our model and data in order to have information." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Backend: Shap TreeExplainer\n" ] } ], "source": [ "xpl.compile(x=Xtest, y_pred=y_pred)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now use our explainer to understand model predictions, through plots or data. We also can find our original dataset, before preprocessing." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
AgeEmbarkedFareNameParchPclassSexSibSpTitle
PassengerId
86348.0Southampton25.93Swift Frederick Joel (Margaret Welles Barron)0First classfemale0Mrs
22429.5Southampton7.90Nenkoff Christo0Third classmale0Mr
8517.0Southampton10.50Ilett Bertha0Second classfemale0Miss
68129.5Queenstown8.14Peters Katie0Third classfemale0Miss
5367.0Southampton26.25Hart Eva Miriam2Second classfemale0Miss
..............................
50733.0Southampton26.00Quick Frederick Charles (Jane Richards)2Second classfemale0Mrs
46856.0Southampton26.55Smart John Montgomery0First classmale0Mr
74129.5Southampton30.00Hawksford Walter James0First classmale0Mr
35529.5Cherbourg7.22Yousif Wazli0Third classmale0Mr
45052.0Southampton30.50Peuchen Arthur Godfrey0First classmale0Major
\n", "

223 rows × 9 columns

\n", "
" ], "text/plain": [ " Age Embarked Fare \\\n", "PassengerId \n", "863 48.0 Southampton 25.93 \n", "224 29.5 Southampton 7.90 \n", "85 17.0 Southampton 10.50 \n", "681 29.5 Queenstown 8.14 \n", "536 7.0 Southampton 26.25 \n", "... ... ... ... \n", "507 33.0 Southampton 26.00 \n", "468 56.0 Southampton 26.55 \n", "741 29.5 Southampton 30.00 \n", "355 29.5 Cherbourg 7.22 \n", "450 52.0 Southampton 30.50 \n", "\n", " Name Parch \\\n", "PassengerId \n", "863 Swift Frederick Joel (Margaret Welles Barron) 0 \n", "224 Nenkoff Christo 0 \n", "85 Ilett Bertha 0 \n", "681 Peters Katie 0 \n", "536 Hart Eva Miriam 2 \n", "... ... ... \n", "507 Quick Frederick Charles (Jane Richards) 2 \n", "468 Smart John Montgomery 0 \n", "741 Hawksford Walter James 0 \n", "355 Yousif Wazli 0 \n", "450 Peuchen Arthur Godfrey 0 \n", "\n", " Pclass Sex SibSp Title \n", "PassengerId \n", "863 First class female 0 Mrs \n", "224 Third class male 0 Mr \n", "85 Second class female 0 Miss \n", "681 Third class female 0 Miss \n", "536 Second class female 0 Miss \n", "... ... ... ... ... \n", "507 Second class female 0 Mrs \n", "468 First class male 0 Mr \n", "741 First class male 0 Mr \n", "355 Third class male 0 Mr \n", "450 First class male 0 Major \n", "\n", "[223 rows x 9 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xpl.x_init" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All the analysis you can do is in this tutorial : **[Tutorial](https://github.com/MAIF/shapash/blob/master/tutorial/tutorial02-Shapash-overview-in-Jupyter.ipynb)**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Compiling with postprocessing parameter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nevertheless, here we want to add postprocessing to our data to understand them better, and to have a better **explicability**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The syntax for the **postprocessing parameter** is as follow :" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```python\n", "postprocess = {\n", " 'name_of_the_feature': {'type': 'type_of_modification', 'rule': 'rule_to_apply'},\n", " 'second_name_of_features': {'type': 'type_of_modification', 'rule': 'rule_to_apply'},\n", " ...\n", "}\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You have five different types of modifications : \n", "\n", "- 1) **prefix** :
\n", "If you want to modify the beginning of the data. The syntax is \n", "```python\n", "{'features_name': {'type': 'prefix',\n", " 'rule': 'Example : '}\n", "}\n", "```\n", "\n", "- 2) **suffix** :
\n", "If you want to add something at the end of some features, the syntax is similar : \n", "```python\n", "{'features_name': {'type': 'suffix',\n", " 'rule': ' is an example'}\n", "}\n", "```\n", "\n", "- 3) **transcoding** :
\n", "This is a mapping function which modifies categorical variables. The syntax is :\n", "```python\n", "{'features_name': {'type': 'transcoding', \n", " 'rule': {'old_name1': 'new_name1',\n", " 'old_name2': 'new_name2',\n", " ...\n", " }\n", " }\n", "}\n", "```\n", "If you don't map all possible values, those values won't be modified.\n", "\n", "- 4) **regex** :
\n", "If you want to modify strings, you can do it by regular expressions like this:\n", "```python\n", "{'features_name': {'type': 'regex', \n", " 'rule': {'in': '^M',\n", " 'out': 'm'\n", " }\n", " }\n", "}\n", "```\n", "\n", "- 5) **case** :
\n", "If you want to change the case of a certain features, you can or change everything in lowercase with `'rule': 'lower'`, or change in uppercase with `'rule': 'upper'`. The syntax is :\n", "```python\n", "{'features_name': {'type': 'case', \n", " 'rule': 'upper'}\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Of course, you don't have to modify all features. Let's give an example." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "postprocess = {\n", " 'Age': {'type': 'suffix', \n", " 'rule': ' years old' # Adding 'years old' at the end\n", " }, \n", " 'Sex': {'type': 'transcoding', \n", " 'rule': {'male': 'Man',\n", " 'female': 'Woman'}\n", " },\n", " 'Pclass': {'type': 'regex', \n", " 'rule': {'in': ' class$', \n", " 'out': ''} # Deleting 'class' word at the end\n", " },\n", " 'Fare': {'type': 'prefix', \n", " 'rule': '$' # Adding $ at the beginning\n", " }, \n", " 'Embarked': {'type': 'case', \n", " 'rule': 'upper'\n", " }\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can now add this postprocess dict in parameter :" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "xpl_postprocess = SmartExplainer(\n", " model=classifier,\n", " postprocessing=postprocess,\n", " preprocessing=encoder, # Optional: compile step can use inverse_transform method\n", " features_dict=titanic_dict\n", ")" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Backend: Shap TreeExplainer\n" ] } ], "source": [ "xpl_postprocess.compile(\n", " x=Xtest,\n", " y_pred=y_pred, # Optional\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can now visualize your dataset, which is modified." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
AgeEmbarkedFareNameParchPclassSexSibSpTitle
PassengerId
86348.0 years oldSOUTHAMPTON$25.93Swift Frederick Joel (Margaret Welles Barron)0FirstWoman0Mrs
22429.5 years oldSOUTHAMPTON$7.9Nenkoff Christo0ThirdMan0Mr
8517.0 years oldSOUTHAMPTON$10.5Ilett Bertha0SecondWoman0Miss
68129.5 years oldQUEENSTOWN$8.14Peters Katie0ThirdWoman0Miss
5367.0 years oldSOUTHAMPTON$26.25Hart Eva Miriam2SecondWoman0Miss
..............................
50733.0 years oldSOUTHAMPTON$26.0Quick Frederick Charles (Jane Richards)2SecondWoman0Mrs
46856.0 years oldSOUTHAMPTON$26.55Smart John Montgomery0FirstMan0Mr
74129.5 years oldSOUTHAMPTON$30.0Hawksford Walter James0FirstMan0Mr
35529.5 years oldCHERBOURG$7.22Yousif Wazli0ThirdMan0Mr
45052.0 years oldSOUTHAMPTON$30.5Peuchen Arthur Godfrey0FirstMan0Major
\n", "

223 rows × 9 columns

\n", "
" ], "text/plain": [ " Age Embarked Fare \\\n", "PassengerId \n", "863 48.0 years old SOUTHAMPTON $25.93 \n", "224 29.5 years old SOUTHAMPTON $7.9 \n", "85 17.0 years old SOUTHAMPTON $10.5 \n", "681 29.5 years old QUEENSTOWN $8.14 \n", "536 7.0 years old SOUTHAMPTON $26.25 \n", "... ... ... ... \n", "507 33.0 years old SOUTHAMPTON $26.0 \n", "468 56.0 years old SOUTHAMPTON $26.55 \n", "741 29.5 years old SOUTHAMPTON $30.0 \n", "355 29.5 years old CHERBOURG $7.22 \n", "450 52.0 years old SOUTHAMPTON $30.5 \n", "\n", " Name Parch Pclass \\\n", "PassengerId \n", "863 Swift Frederick Joel (Margaret Welles Barron) 0 First \n", "224 Nenkoff Christo 0 Third \n", "85 Ilett Bertha 0 Second \n", "681 Peters Katie 0 Third \n", "536 Hart Eva Miriam 2 Second \n", "... ... ... ... \n", "507 Quick Frederick Charles (Jane Richards) 2 Second \n", "468 Smart John Montgomery 0 First \n", "741 Hawksford Walter James 0 First \n", "355 Yousif Wazli 0 Third \n", "450 Peuchen Arthur Godfrey 0 First \n", "\n", " Sex SibSp Title \n", "PassengerId \n", "863 Woman 0 Mrs \n", "224 Man 0 Mr \n", "85 Woman 0 Miss \n", "681 Woman 0 Miss \n", "536 Woman 0 Miss \n", "... ... ... ... \n", "507 Woman 0 Mrs \n", "468 Man 0 Mr \n", "741 Man 0 Mr \n", "355 Man 0 Mr \n", "450 Man 0 Major \n", "\n", "[223 rows x 9 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xpl_postprocess.x_init" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All the plots are also modified with the postprocessing modifications." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Application with to_pandas method" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The main purpose of postprocessing modifications is a better understanding of the data, especially when the features names are not specified, such as in to_pandas() method, which orders the features depending on their importance." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "to_pandas params: {'features_to_hide': None, 'threshold': None, 'positive': None, 'max_contrib': 20}\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
predfeature_1value_1contribution_1feature_2value_2contribution_2feature_3value_3contribution_3...contribution_6feature_7value_7contribution_7feature_8value_8contribution_8feature_9value_9contribution_9
8631Title of passengerMrs0.163479SexWoman0.154309Ticket classFirst0.130221...0.0406219Name, First nameSwift Frederick Joel (Margaret Welles Barron)-0.0381955Port of embarkationSOUTHAMPTON-0.0147327Relatives like children or parents0-0.00538103
2240Title of passengerMr0.094038SexMan0.0696282Age29.5 years old0.0658556...0.0151605Relatives such as brother or wife0-0.00855039Relatives like children or parents00.00124433Name, First nameNenkoff Christo-0.000577095
851Title of passengerMiss0.190529SexWoman0.135507Ticket classSecond0.0809714...-0.025286Relatives like children or parents0-0.0238222Relatives such as brother or wife00.0209045Age17.0 years old-0.00702283
6811Title of passengerMiss0.237477Port of embarkationQUEENSTOWN0.143451SexWoman0.127931...0.0243567Relatives like children or parents00.0165205Passenger fare$8.14-0.0109633Age29.5 years old0.00327866
5361Title of passengerMiss0.210166Ticket classSecond0.168247SexWoman0.0876445...0.0147503Relatives like children or parents20.0125069Port of embarkationSOUTHAMPTON-0.0119119Name, First nameHart Eva Miriam0.00654165
..................................................................
5071Title of passengerMrs0.215332SexWoman0.194419Ticket classSecond0.166437...-0.0079185Relatives like children or parents20.00407485Age33.0 years old-0.00263589Name, First nameQuick Frederick Charles (Jane Richards)0.00162901
4680SexMan0.100602Passenger fare$26.55-0.099794Title of passengerMr0.0967768...0.0243706Port of embarkationSOUTHAMPTON0.0124424Relatives such as brother or wife0-0.0108301Relatives like children or parents0-0.00332632
7410Title of passengerMr0.131861SexMan0.110845Age29.5 years old0.104878...0.0339308Relatives such as brother or wife0-0.00715564Name, First nameHawksford Walter James0.00165882Relatives like children or parents0-0.00137946
3550Title of passengerMr0.12679SexMan0.0933251Age29.5 years old0.0717939...-0.0271103Name, First nameYousif Wazli0.0163174Relatives such as brother or wife0-0.0108501Relatives like children or parents0-0.000543508
4500SexMan0.13572Title of passengerMajor-0.0723023Age52.0 years old0.0690373...0.027384Relatives such as brother or wife0-0.0134144Relatives like children or parents00.00256623Name, First namePeuchen Arthur Godfrey0.00229483
\n", "

223 rows × 28 columns

\n", "
" ], "text/plain": [ " pred feature_1 value_1 contribution_1 feature_2 \\\n", "863 1 Title of passenger Mrs 0.163479 Sex \n", "224 0 Title of passenger Mr 0.094038 Sex \n", "85 1 Title of passenger Miss 0.190529 Sex \n", "681 1 Title of passenger Miss 0.237477 Port of embarkation \n", "536 1 Title of passenger Miss 0.210166 Ticket class \n", ".. ... ... ... ... ... \n", "507 1 Title of passenger Mrs 0.215332 Sex \n", "468 0 Sex Man 0.100602 Passenger fare \n", "741 0 Title of passenger Mr 0.131861 Sex \n", "355 0 Title of passenger Mr 0.12679 Sex \n", "450 0 Sex Man 0.13572 Title of passenger \n", "\n", " value_2 contribution_2 feature_3 value_3 \\\n", "863 Woman 0.154309 Ticket class First \n", "224 Man 0.0696282 Age 29.5 years old \n", "85 Woman 0.135507 Ticket class Second \n", "681 QUEENSTOWN 0.143451 Sex Woman \n", "536 Second 0.168247 Sex Woman \n", ".. ... ... ... ... \n", "507 Woman 0.194419 Ticket class Second \n", "468 $26.55 -0.099794 Title of passenger Mr \n", "741 Man 0.110845 Age 29.5 years old \n", "355 Man 0.0933251 Age 29.5 years old \n", "450 Major -0.0723023 Age 52.0 years old \n", "\n", " contribution_3 ... contribution_6 feature_7 \\\n", "863 0.130221 ... 0.0406219 Name, First name \n", "224 0.0658556 ... 0.0151605 Relatives such as brother or wife \n", "85 0.0809714 ... -0.025286 Relatives like children or parents \n", "681 0.127931 ... 0.0243567 Relatives like children or parents \n", "536 0.0876445 ... 0.0147503 Relatives like children or parents \n", ".. ... ... ... ... \n", "507 0.166437 ... -0.0079185 Relatives like children or parents \n", "468 0.0967768 ... 0.0243706 Port of embarkation \n", "741 0.104878 ... 0.0339308 Relatives such as brother or wife \n", "355 0.0717939 ... -0.0271103 Name, First name \n", "450 0.0690373 ... 0.027384 Relatives such as brother or wife \n", "\n", " value_7 contribution_7 \\\n", "863 Swift Frederick Joel (Margaret Welles Barron) -0.0381955 \n", "224 0 -0.00855039 \n", "85 0 -0.0238222 \n", "681 0 0.0165205 \n", "536 2 0.0125069 \n", ".. ... ... \n", "507 2 0.00407485 \n", "468 SOUTHAMPTON 0.0124424 \n", "741 0 -0.00715564 \n", "355 Yousif Wazli 0.0163174 \n", "450 0 -0.0134144 \n", "\n", " feature_8 value_8 \\\n", "863 Port of embarkation SOUTHAMPTON \n", "224 Relatives like children or parents 0 \n", "85 Relatives such as brother or wife 0 \n", "681 Passenger fare $8.14 \n", "536 Port of embarkation SOUTHAMPTON \n", ".. ... ... \n", "507 Age 33.0 years old \n", "468 Relatives such as brother or wife 0 \n", "741 Name, First name Hawksford Walter James \n", "355 Relatives such as brother or wife 0 \n", "450 Relatives like children or parents 0 \n", "\n", " contribution_8 feature_9 \\\n", "863 -0.0147327 Relatives like children or parents \n", "224 0.00124433 Name, First name \n", "85 0.0209045 Age \n", "681 -0.0109633 Age \n", "536 -0.0119119 Name, First name \n", ".. ... ... \n", "507 -0.00263589 Name, First name \n", "468 -0.0108301 Relatives like children or parents \n", "741 0.00165882 Relatives like children or parents \n", "355 -0.0108501 Relatives like children or parents \n", "450 0.00256623 Name, First name \n", "\n", " value_9 contribution_9 \n", "863 0 -0.00538103 \n", "224 Nenkoff Christo -0.000577095 \n", "85 17.0 years old -0.00702283 \n", "681 29.5 years old 0.00327866 \n", "536 Hart Eva Miriam 0.00654165 \n", ".. ... ... \n", "507 Quick Frederick Charles (Jane Richards) 0.00162901 \n", "468 0 -0.00332632 \n", "741 0 -0.00137946 \n", "355 0 -0.000543508 \n", "450 Peuchen Arthur Godfrey 0.00229483 \n", "\n", "[223 rows x 28 columns]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xpl_postprocess.to_pandas()" ] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.11" } }, "nbformat": 4, "nbformat_minor": 4 }