{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Features importance\n",
"\n",
"The methode *features_importance* displays a bar chart representing the
\n",
"sum of absolute contribution values of each feature.\n",
"\n",
"This method also makes it possible to represent this sum calculated
\n",
"on a subset and to compare it with the total population\n",
"\n",
"This short tutorial presents the different parameters you can use.\n",
"\n",
"Content :\n",
"- Classification case: Specify the target modality to display.\n",
"- selection parameter to display a subset\n",
"- max_features parameter limits the number of features \n",
"\n",
"We used Kaggle's [Titanic](https://www.kaggle.com/c/titanic/data) dataset"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from category_encoders import OrdinalEncoder\n",
"from sklearn.ensemble import ExtraTreesClassifier\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",
"del titanic_df['Name']\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", "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", "