{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <span style=\"color:#7A5197;\">***Spaceship Titanic***<span>\n\n\n### <span style=\"color:#7A5197;\">*Table of content*<span>\n<a id=\"table-of-contents\"></a>\n- [1. Introduction](#1)\n    - [1.1 Storytelling](#1.1)\n    - [1.2 Storytelling](#1.2)\n- [2. Preparations](#2)\n- [3. Dataset Overview](#3)\n    - [3.1 Train Dataset](#3.1)\n        - [3.1.1 Quick view](#3.1.1)\n        - [3.1.2 Data types](#3.1.2)\n        - [3.1.3 Basic Statistics](#3.1.3)\n        - [3.1.4 Target Column](#3.1.4)\n    - [3.2 Test Dataset](#3.2)\n        - [3.2.1 Quick view](#3.2.1)\n        - [3.2.2 Data types](#3.2.2)\n        - [3.2.3 Basic Statistics](#3.2.3)\n    - [3.3 Submission](#3.3)\n- [4. Explore Data Analisys](#4)\n    - [4.1 Transported](#4.1)\n    - [4.2 HomePlanet](#4.2)\n    - [4.3 CryoSleep](#4.3)\n    - [4.4 Cabins](#4.4)\n    - [4.5 Destination](#4.5)\n    - [4.6 Age](#4.6)\n    - [4.7 VIP](#4.7)\n    - [4.8 RoomService](#4.8)\n    - [4.9 FoodCourt](#4.9)\n    - [4.10 ShoppingMall](#4.10)\n    - [4.11 SPA](#4.11)\n    - [4.12 VRDeck](#4.12)\n- [5. Reference](#5)    ","metadata":{"papermill":{"duration":0.059732,"end_time":"2022-03-26T15:40:48.184429","exception":false,"start_time":"2022-03-26T15:40:48.124697","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"1\"></a>\n# **<span style=\"color:#7A5197;\">1. Introduction</span>**\n<a id=\"1.1\"></a>\n### **<span style=\"color:#7A5197;\"> 1.1 Storytelling </span>**\n\n\n> _\"There are no barriers to human… \"_ - (c) Sergei Pavlovich Korolev\n \n \nWelcome to the year 2912, where your data science skills are needed to solve a cosmic mystery. We've received a transmission from four lightyears away and things aren't looking good.\n\nThe Spaceship Titanic was an interstellar passenger liner launched a month ago. With almost 13,000 passengers on board, the vessel set out on its maiden voyage transporting emigrants from our solar system to three newly habitable exoplanets orbiting nearby stars.\n\nWhile rounding Alpha Centauri en route to its first destination—the torrid 55 Cancri E—the unwary Spaceship Titanic collided with a spacetime anomaly hidden within a dust cloud. Sadly, it met a similar fate as its namesake from 1000 years before. Though the ship stayed intact, almost half of the passengers were transported to an alternate dimension!\n\n[back to top](#table-of-contents)\n<a id=\"1.2\"></a>\n### **<span style=\"color:#7A5197;\"> 1.2 Evaluation </span>**\n\nSubmissions are evaluated based on their classification accuracy, the percentage of predicted labels that are correct.\n\n\n$ \\text{Accuracy} = \\frac{\\text{TP} + \\text{TN}}{\\text{TP} + \\text{TN} + \\text{FP} + \\text{FN}}$","metadata":{"papermill":{"duration":0.049977,"end_time":"2022-03-26T15:40:48.293158","exception":false,"start_time":"2022-03-26T15:40:48.243181","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"2\"></a>\n# **<span style=\"color:#7A5197;\">2. Preparations</span>**\n\nPreparing packages and data that will be used in the analysis process. Packages that will be loaded are mainly for data manipulation, data visualization and modeling. There are 2 datasets that are used in the analysis, they are train and test dataset. The main use of train dataset is to train models and use it to predict test dataset. While sample submission file is used to informed participants on the expected submission for the competition. (to see the details, please expand)\n","metadata":{"papermill":{"duration":0.047907,"end_time":"2022-03-26T15:40:48.389267","exception":false,"start_time":"2022-03-26T15:40:48.34136","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# import packages\nimport pandas as pd\nimport numpy as np\nfrom matplotlib import pyplot as plt\nimport seaborn as sns\nfrom mpl_toolkits.mplot3d import Axes3D\n\n# setting up options\nimport warnings\npd.set_option('display.max_rows', None)\npd.set_option('display.max_columns', None)\nwarnings.filterwarnings('ignore')\nfrom cycler import cycler\nfrom IPython.core.display import HTML\n\n\n# read datasets\ntrain_df = pd.read_csv('../input/spaceship-titanic/train.csv')\ntest_df = pd.read_csv('../input/spaceship-titanic/test.csv')\nssub = pd.read_csv('../input/spaceship-titanic/sample_submission.csv')\n\nfeatures = [col for col in test_df if col not in ['PassengerId']]\n\ndef multi_table(table_list):\n    return HTML(\n        f\"<table><tr> {''.join(['<td>' + table._repr_html_() + '</td>' for table in table_list])} </tr></table>\")\n\ndef formatter(v):\n    if type(v) is str:\n        return v\n    if pd.isna(v) or v <= 0:\n        return ''\n    if v == int(v):\n        return f'{v:.0f}'\n    return f'{v:.1f}'","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2022-03-26T15:40:48.491501Z","iopub.status.busy":"2022-03-26T15:40:48.490274Z","iopub.status.idle":"2022-03-26T15:40:49.65644Z","shell.execute_reply":"2022-03-26T15:40:49.657032Z","shell.execute_reply.started":"2022-03-25T21:16:21.286611Z"},"papermill":{"duration":1.219843,"end_time":"2022-03-26T15:40:49.657347","exception":false,"start_time":"2022-03-26T15:40:48.437504","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3\"></a>\n# **<span style=\"color:#7A5197;\">3. Dataset Overview</span>**\n\nThe intend of the overview is to get a feel of the data and its structure in train, test and submission file. An overview on train and test datasets will include a quick analysis on missing values and basic statistics, while sample submission will be loaded to see the expected submission.\n\n|Variable|Definition|\n|------|---|\n|PassengerId|A unique Id for each passenger. Each Id takes the form gggg_pp where gggg indicates a group the passenger is travelling with and pp is their number within the group. People in a group are often family members, but not always.||\n|HomePlanet|The planet the passenger departed from, typically their planet of permanent residence.|\n|CryoSleep|Indicates whether the passenger elected to be put into suspended animation for the duration of the voyage. Passengers in cryosleep are confined to their cabins.HomePlanet||\n|Cabin|The cabin number where the passenger is staying. Takes the form deck/num/side, where side can be either P for Port or S for Starboard.||\n|Destination|The planet the passenger will be debarking to.||\n|Age|The age of the passenger.||\n|VIP|Whether the passenger has paid for special VIP service during the voyage.||\n|RoomService, FoodCourt, ShoppingMall, Spa, VRDeck|Amount the passenger has billed at each of the Spaceship Titanic's many luxury amenities.||\n|Name|The first and last names of the passenger.||\n|Transported|Whether the passenger was transported to another dimension. This is the target, the column you are trying to predict.||\n\n[back to top](#table-of-contents)\n<a id=\"3\"></a>\n### **<span style=\"color:#7A5197;\">3.1 Train Dataset</span>**\n\nAs stated before, train dataset is mainly used to train predictive model as there is an available target variable in this set. This dataset is also used to explore more on the data itself including find a relation between each predictors and the target variable.\n\n__Observations:__\n* There are two class to predicted.  (`True` or `False`)\n* All features (not include index and target) have missing values. (`NaN`, `Null` and `zeros`)\n* `CryoSleep` an `VIP` needs repalce from object to bool data type.","metadata":{"papermill":{"duration":0.048436,"end_time":"2022-03-26T15:40:49.754349","exception":false,"start_time":"2022-03-26T15:40:49.705913","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.1.1\"></a>\n#### **<span style=\"color:#7A5197;\">3.1.1 Quick view</span>**\n","metadata":{"papermill":{"duration":0.050136,"end_time":"2022-03-26T15:40:49.854655","exception":false,"start_time":"2022-03-26T15:40:49.804519","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:49.966535Z","iopub.status.busy":"2022-03-26T15:40:49.96583Z","iopub.status.idle":"2022-03-26T15:40:49.989428Z","shell.execute_reply":"2022-03-26T15:40:49.989972Z","shell.execute_reply.started":"2022-03-25T21:16:22.48917Z"},"papermill":{"duration":0.085633,"end_time":"2022-03-26T15:40:49.990151","exception":false,"start_time":"2022-03-26T15:40:49.904518","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Number of rows: {train_df.shape[0]};  Number of columns: {train_df.shape[1]}; No of missing values: {sum(train_df.isna().sum())}')\ntrain_df.isna().sum()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:50.09716Z","iopub.status.busy":"2022-03-26T15:40:50.096387Z","iopub.status.idle":"2022-03-26T15:40:50.121331Z","shell.execute_reply":"2022-03-26T15:40:50.121987Z","shell.execute_reply.started":"2022-03-25T21:16:22.526224Z"},"papermill":{"duration":0.07889,"end_time":"2022-03-26T15:40:50.122167","exception":false,"start_time":"2022-03-26T15:40:50.043277","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.1.2\"></a>\n#### **<span style=\"color:#7A5197;\">3.1.2 Data types</span>**\n","metadata":{"papermill":{"duration":0.049522,"end_time":"2022-03-26T15:40:50.227948","exception":false,"start_time":"2022-03-26T15:40:50.178426","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_df.dtypes","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:50.336533Z","iopub.status.busy":"2022-03-26T15:40:50.335648Z","iopub.status.idle":"2022-03-26T15:40:50.339058Z","shell.execute_reply":"2022-03-26T15:40:50.339601Z","shell.execute_reply.started":"2022-03-25T21:16:22.554177Z"},"papermill":{"duration":0.061987,"end_time":"2022-03-26T15:40:50.339857","exception":false,"start_time":"2022-03-26T15:40:50.27787","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.1.3\"></a>\n#### **<span style=\"color:#7A5197;\">3.1.3 Basic Statistics</span>**\nBelow is the basic statistics for each variables which contain information on count, mean, standard deviation, minimum, 1st quartile, median, 3rd quartile and maximum.","metadata":{"papermill":{"duration":0.05005,"end_time":"2022-03-26T15:40:50.440868","exception":false,"start_time":"2022-03-26T15:40:50.390818","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_df.describe()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:50.546037Z","iopub.status.busy":"2022-03-26T15:40:50.545366Z","iopub.status.idle":"2022-03-26T15:40:50.581825Z","shell.execute_reply":"2022-03-26T15:40:50.582406Z","shell.execute_reply.started":"2022-03-25T21:16:22.562695Z"},"papermill":{"duration":0.090674,"end_time":"2022-03-26T15:40:50.582578","exception":false,"start_time":"2022-03-26T15:40:50.491904","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.1.3\"></a>\n#### **<span style=\"color:#7A5197;\">3.1.4 Target Column</span>**\n","metadata":{"papermill":{"duration":0.051562,"end_time":"2022-03-26T15:40:50.685448","exception":false,"start_time":"2022-03-26T15:40:50.633886","status":"completed"},"tags":[]}},{"cell_type":"code","source":"print('Target column basic statistics:')\ntrain_df['Transported'].describe()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:50.790801Z","iopub.status.busy":"2022-03-26T15:40:50.790121Z","iopub.status.idle":"2022-03-26T15:40:50.79989Z","shell.execute_reply":"2022-03-26T15:40:50.800454Z","shell.execute_reply.started":"2022-03-25T21:16:22.609769Z"},"papermill":{"duration":0.064255,"end_time":"2022-03-26T15:40:50.800628","exception":false,"start_time":"2022-03-26T15:40:50.736373","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Frequency of each target classes:')\ntrain_df['Transported'].value_counts()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:50.925365Z","iopub.status.busy":"2022-03-26T15:40:50.920136Z","iopub.status.idle":"2022-03-26T15:40:50.92997Z","shell.execute_reply":"2022-03-26T15:40:50.929432Z","shell.execute_reply.started":"2022-03-25T21:16:22.620976Z"},"papermill":{"duration":0.068253,"end_time":"2022-03-26T15:40:50.930123","exception":false,"start_time":"2022-03-26T15:40:50.86187","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.2\"></a>\n### **<span style=\"color:#7A5197;\">3.2 Test Dataset</span>**\nTest dataset is used to make a prediction based on the model that has previously trained. Exploration in this dataset is also needed to see how the data is structured and especially on it’s similiarity with the train dataset.\n\n__Observations:__\n* Observations in the `train` dataset are still consistent in the `test` dataset.\n\n","metadata":{"papermill":{"duration":0.054589,"end_time":"2022-03-26T15:40:51.040327","exception":false,"start_time":"2022-03-26T15:40:50.985738","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.2.1\"></a>\n#### **<span style=\"color:#7A5197;\">3.2.1 Quick view</span>**\n","metadata":{"papermill":{"duration":0.052831,"end_time":"2022-03-26T15:40:51.151796","exception":false,"start_time":"2022-03-26T15:40:51.098965","status":"completed"},"tags":[]}},{"cell_type":"code","source":"test_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:51.260694Z","iopub.status.busy":"2022-03-26T15:40:51.259698Z","iopub.status.idle":"2022-03-26T15:40:51.279414Z","shell.execute_reply":"2022-03-26T15:40:51.279947Z","shell.execute_reply.started":"2022-03-25T21:16:22.635195Z"},"papermill":{"duration":0.075804,"end_time":"2022-03-26T15:40:51.28012","exception":false,"start_time":"2022-03-26T15:40:51.204316","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.2.2\"></a>\n#### **<span style=\"color:#7A5197;\">3.2.2 Data types</span>**","metadata":{"papermill":{"duration":0.052456,"end_time":"2022-03-26T15:40:51.38647","exception":false,"start_time":"2022-03-26T15:40:51.334014","status":"completed"},"tags":[]}},{"cell_type":"code","source":"test_df.dtypes","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:51.496194Z","iopub.status.busy":"2022-03-26T15:40:51.495285Z","iopub.status.idle":"2022-03-26T15:40:51.502056Z","shell.execute_reply":"2022-03-26T15:40:51.502541Z","shell.execute_reply.started":"2022-03-25T21:16:22.662355Z"},"papermill":{"duration":0.06318,"end_time":"2022-03-26T15:40:51.502703","exception":false,"start_time":"2022-03-26T15:40:51.439523","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3.2.3\"></a>\n#### **<span style=\"color:#7A5197;\">3.2.3 Basic Statistics</span>**\nBelow is the basic statistics for each variables which contain information on count, mean, standard deviation, minimum, 1st quartile, median, 3rd quartile and maximum.","metadata":{"papermill":{"duration":0.052982,"end_time":"2022-03-26T15:40:51.609158","exception":false,"start_time":"2022-03-26T15:40:51.556176","status":"completed"},"tags":[]}},{"cell_type":"code","source":"test_df.describe()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:51.719566Z","iopub.status.busy":"2022-03-26T15:40:51.718587Z","iopub.status.idle":"2022-03-26T15:40:51.748398Z","shell.execute_reply":"2022-03-26T15:40:51.748942Z","shell.execute_reply.started":"2022-03-25T21:16:22.798425Z"},"papermill":{"duration":0.086514,"end_time":"2022-03-26T15:40:51.749114","exception":false,"start_time":"2022-03-26T15:40:51.6626","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"3\"></a>\n### **<span style=\"color:#7A5197;\">3.3 Submission</span>**\nBelow is the first 5 rows of submission file:","metadata":{"papermill":{"duration":0.05491,"end_time":"2022-03-26T15:40:51.860182","exception":false,"start_time":"2022-03-26T15:40:51.805272","status":"completed"},"tags":[]}},{"cell_type":"code","source":"ssub.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:51.989626Z","iopub.status.busy":"2022-03-26T15:40:51.988902Z","iopub.status.idle":"2022-03-26T15:40:51.991679Z","shell.execute_reply":"2022-03-26T15:40:51.99218Z","shell.execute_reply.started":"2022-03-25T21:16:22.960026Z"},"papermill":{"duration":0.073729,"end_time":"2022-03-26T15:40:51.992365","exception":false,"start_time":"2022-03-26T15:40:51.918636","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4\"></a>\n# **<span style=\"color:#7A5197;\">4. Explore Data Analisys</span>**\n\n<a id=\"4.1\"></a>\n### **<span style=\"color:#7A5197;\">4.1 Transported</span>**\n\nTarget value is binary, 49.64% passengers were transported to an alternate dimension!","metadata":{"papermill":{"duration":0.058562,"end_time":"2022-03-26T15:40:52.10895","exception":false,"start_time":"2022-03-26T15:40:52.050388","status":"completed"},"tags":[]}},{"cell_type":"code","source":"plt.subplots(figsize=(25, 10), facecolor='#f6f5f5')\nplt.pie(train_df.Transported.value_counts(), startangle=90, wedgeprops={'width':0.3}, colors=['#F5C63C', '#7A5197'] )\nplt.title('Target Balance Pie Chart', loc='center', fontsize=24, color='#7A5197', fontweight='bold')\nplt.text(0, 0, f\"{train_df.Transported.value_counts()[0] / train_df.Transported.count() * 100:.2f}%\", ha='center', va='center', fontweight='bold', fontsize=42, color='#7A5197')\nplt.legend(train_df.Transported.value_counts().index, ncol=2, facecolor='#f6f5f5', edgecolor='#f6f5f5', loc='lower center', fontsize=16)\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:52.229407Z","iopub.status.busy":"2022-03-26T15:40:52.228297Z","iopub.status.idle":"2022-03-26T15:40:52.468465Z","shell.execute_reply":"2022-03-26T15:40:52.469364Z","shell.execute_reply.started":"2022-03-25T21:16:23.143631Z"},"papermill":{"duration":0.30243,"end_time":"2022-03-26T15:40:52.46965","exception":false,"start_time":"2022-03-26T15:40:52.16722","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.2\"></a>\n### **<span style=\"color:#7A5197;\">4.2 HomePlanet</span>**\n\nThe most part of passengers from Earth. Also as we can see below residents from Europa was transported more then others.\n* 57.6% mistransported passengers from Earth in relation to fellow countrymans -> Probably residents Earth is not able to get safely cabins.\n* 34.1% mistransported passengers from Europe in relation to fellow countrymans -> Reverse effect.\n___\n* 31.2% residents Earth wasnt transported in relation to all.\n___\n* 54.2% residents Earth.\n* 25.1% residents from Europe.\n* 20.7% residents from Mars.","metadata":{"papermill":{"duration":0.055509,"end_time":"2022-03-26T15:40:52.586234","exception":false,"start_time":"2022-03-26T15:40:52.530725","status":"completed"},"tags":[]}},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(9, 5), facecolor=facecolor)\ncolors = ['#7A5197', '#BB5098', '#5344A9', '#F5C63C', '#F47F6B']\n\nfor i, t_val in enumerate(train_df.Transported.unique()):\n    ax = fig.add_subplot(2, 2, i+1, facecolor=facecolor)\n    _pivot_df = pd.pivot_table(train_df[train_df['Transported'] == t_val], index='HomePlanet', aggfunc='count', values='Transported')\n    ax.barh(_pivot_df.index, _pivot_df['Transported'], color=colors[i])\n    _target_col = {False: 'Mistransported', True: 'Transported'}\n    ax.set_title(_target_col[t_val], fontsize=12, fontweight=\"medium\")\n    ax.tick_params(left=False, bottom=False, right=False, top=False, labelleft=(i<=1))\n    ax.xaxis.set_ticks([])\n    \n    for _, spine in ax.spines.items():\n        spine.set_visible(False)\n        \n    if i != 0:\n        ax.yaxis.set_ticks([])\n    else:\n        pass\n    for ind, val in enumerate(_pivot_df['Transported']):\n        #print(val)\n        ax.text(0, ind, formatter(val), fontweight=\"bold\", color=facecolor, fontsize=14)\n    \nfig.text(0.1, 1.08,'Bar Plot Count of Passengers',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.1, 1,'From Home Planets ',fontweight='bold', fontsize=24, color='#7A5197');\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:52.702901Z","iopub.status.busy":"2022-03-26T15:40:52.701902Z","iopub.status.idle":"2022-03-26T15:40:52.908673Z","shell.execute_reply":"2022-03-26T15:40:52.909641Z","shell.execute_reply.started":"2022-03-25T21:16:23.39702Z"},"papermill":{"duration":0.267033,"end_time":"2022-03-26T15:40:52.909965","exception":false,"start_time":"2022-03-26T15:40:52.642932","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Percentage of mistransported passengers in relation to all')\n_ = pd.pivot_table(train_df[train_df['Transported'] == False], index='HomePlanet', aggfunc='count', values='Transported')['Transported'] / train_df['CryoSleep'].count() * 100\n_pivot_1 =  pd.DataFrame(_).style.background_gradient(cmap='BuPu')\n\nprint('Percentage of mistransported passengers in relation to fellow countrymans')\n_ = pd.pivot_table(train_df[train_df['Transported'] == False], index='HomePlanet', aggfunc='count', values='Transported')['Transported'] / pd.pivot_table(train_df, index='HomePlanet', aggfunc='count', values='Transported')['Transported'] * 100\n_pivot_2 = pd.DataFrame(_).style.background_gradient(cmap='BuPu')\n\nmulti_table([_pivot_1, _pivot_2])","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:53.062325Z","iopub.status.busy":"2022-03-26T15:40:53.061229Z","iopub.status.idle":"2022-03-26T15:40:53.166182Z","shell.execute_reply":"2022-03-26T15:40:53.16551Z","shell.execute_reply.started":"2022-03-25T21:16:23.575082Z"},"papermill":{"duration":0.174386,"end_time":"2022-03-26T15:40:53.166338","exception":false,"start_time":"2022-03-26T15:40:52.991952","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.3\"></a>\n### **<span style=\"color:#7A5197;\">4.3 CryoSleep</span>**\n\n\n* 30.7% passengers from Earth with option CryoSleep in relation to fellow countrymans. -> The hypothesis that Earth residents live poorer than those from Mars and Europe is look true.\n* 43.9% passengers from Europe with option CryoSleep in relation to fellow countrymans. \n___\n* 16.3% residents Earth with option CryoSleep in relation to all.","metadata":{"papermill":{"duration":0.06051,"end_time":"2022-03-26T15:40:53.289591","exception":false,"start_time":"2022-03-26T15:40:53.229081","status":"completed"},"tags":[]}},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(9, 5), facecolor=facecolor)\ncolors = ['#7A5197', '#BB5098', '#5344A9', '#F5C63C', '#F47F6B']\n\nfor i, t_val in enumerate(train_df.Transported.unique()):\n    ax = fig.add_subplot(2, 2, i+1, facecolor=facecolor)\n    _pivot_df = pd.pivot_table(train_df[train_df['CryoSleep'] == t_val], index='HomePlanet', aggfunc='count', values='CryoSleep')\n    ax.barh(_pivot_df.index, _pivot_df['CryoSleep'], color=colors[i])\n    _target_col = {False: 'Without CryoSleep', True: 'CryoSleep'}\n    ax.set_title(_target_col[t_val], fontsize=12, fontweight=\"medium\")\n    ax.tick_params(left=False, bottom=False, right=False, top=False, labelleft=(i<=1))\n    ax.xaxis.set_ticks([])\n    \n    for _, spine in ax.spines.items():\n        spine.set_visible(False)\n        \n    if i != 0:\n        ax.yaxis.set_ticks([])\n    else:\n        pass\n    for ind, val in enumerate(_pivot_df['CryoSleep']):\n        #print(val)\n        ax.text(0, ind, formatter(val), fontweight=\"bold\", color=facecolor, fontsize=14)\n    \nfig.text(0.1, 1.08,'Bar Plot Count of Passengers',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.1, 1,'With Option CryoSleep ',fontweight='bold', fontsize=24, color='#7A5197');\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:53.423773Z","iopub.status.busy":"2022-03-26T15:40:53.420053Z","iopub.status.idle":"2022-03-26T15:40:53.633573Z","shell.execute_reply":"2022-03-26T15:40:53.634411Z","shell.execute_reply.started":"2022-03-25T21:16:23.689989Z"},"papermill":{"duration":0.283739,"end_time":"2022-03-26T15:40:53.634699","exception":false,"start_time":"2022-03-26T15:40:53.35096","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Percentage of Passengers with Option CryoSleep  in relation to all')\n_ = pd.pivot_table(train_df[train_df['CryoSleep'] == True], index='HomePlanet', aggfunc='count', values='CryoSleep')['CryoSleep'] / train_df['CryoSleep'].count() * 100\n_pivot_1 = pd.DataFrame(_).style.background_gradient(cmap='BuPu')\n\nprint('Percentage of Passengers with Option CryoSleep in relation to fellow countrymans')\n_ = pd.pivot_table(train_df[train_df['CryoSleep'] == True], index='HomePlanet', aggfunc='count', values='CryoSleep')['CryoSleep'] / pd.pivot_table(train_df, index='HomePlanet', aggfunc='count', values='CryoSleep')['CryoSleep'] * 100\n_pivot_2 = pd.DataFrame(_).style.background_gradient(cmap='BuPu')\n\nmulti_table([_pivot_1, _pivot_2])","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:53.790595Z","iopub.status.busy":"2022-03-26T15:40:53.789899Z","iopub.status.idle":"2022-03-26T15:40:53.840319Z","shell.execute_reply":"2022-03-26T15:40:53.840989Z","shell.execute_reply.started":"2022-03-25T21:16:23.890597Z"},"papermill":{"duration":0.122226,"end_time":"2022-03-26T15:40:53.841167","exception":false,"start_time":"2022-03-26T15:40:53.718941","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.4\"></a>\n### **<span style=\"color:#7A5197;\">4.4 Cabins</span>**\n\n* CryoSleep option is positive affect to be transported.\n* Residents Earth have worst Deck and probability to be transported.\n* Residents Mars have high dispersion of probability to be transported.\n___\nI have computed difference between transported probabilities within cryosleep option. The more this values, the options to be transported of this Deck for different classes of HomePlanet. \n\n* `D`, `E`, `F` within cryoSleep is optimal to be transported.\n* `B` is optimal in general.\n* `D` and `F` optimal for Mars residents.\n* `S Side`  more optimal to be transported.","metadata":{"papermill":{"duration":0.068065,"end_time":"2022-03-26T15:40:53.974195","exception":false,"start_time":"2022-03-26T15:40:53.90613","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_df = train_df.dropna()\ntrain_df['CabinDeck'] = train_df.Cabin.map(lambda x: x.split('/')[0])\ntrain_df['CabinNum'] = train_df.Cabin.map(lambda x: x.split('/')[1])\ntrain_df['CabinSide'] = train_df.Cabin.map(lambda x: x.split('/')[2])","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:54.117216Z","iopub.status.busy":"2022-03-26T15:40:54.108784Z","iopub.status.idle":"2022-03-26T15:40:54.134488Z","shell.execute_reply":"2022-03-26T15:40:54.135084Z","shell.execute_reply.started":"2022-03-25T21:16:23.950199Z"},"papermill":{"duration":0.097164,"end_time":"2022-03-26T15:40:54.135275","exception":false,"start_time":"2022-03-26T15:40:54.038111","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(14, 2), facecolor=facecolor)\ncolors_deck = ['#2C0735', '#7A5197', '#BB5098', '#4E148C', '#613DC1', '#858AE3','#56CBF9', '#97DFFC', '#F7F4EA']\n\nfor i, t_val in enumerate(train_df.CabinDeck.unique()):\n    ax = fig.add_subplot(1, 9, i+1, facecolor=facecolor)\n    _pivot_df = pd.pivot_table(train_df[train_df['CabinDeck'] == t_val], index='CabinSide', aggfunc='count', values='CryoSleep')\n    ax.barh(_pivot_df.index, _pivot_df['CryoSleep'], color=colors_deck[i])\n    #_target_col = {False: 'Without CryoSleep', True: 'CryoSleep'}\n    #ax.set_title(_target_col[t_val], fontsize=12, fontweight=\"medium\")\n    ax.tick_params(left=False, bottom=False, right=False, top=False, labelleft=(i<=1))\n    ax.xaxis.set_ticks([])\n    \n    for _, spine in ax.spines.items():\n        spine.set_visible(False)\n        \n    if i != 0:\n        ax.yaxis.set_ticks([])\n    else:\n        pass\n    for ind, val in enumerate(_pivot_df['CryoSleep']):\n        #print(val)\n        ax.text(0, ind, formatter(val), fontweight=\"bold\", color=facecolor, fontsize=14)\n    \nfig.text(0.13, 1.20,'Bar Plot Count of Passengers',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.13, 1,'by CabinDeck & CabinSide',fontweight='bold', fontsize=24, color='#7A5197');\nfig.legend(train_df.CabinDeck.unique(), ncol=8, facecolor='#f6f5f5', edgecolor='#f6f5f5',loc='lower center', fontsize=8, framealpha=1)\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:54.267176Z","iopub.status.busy":"2022-03-26T15:40:54.266503Z","iopub.status.idle":"2022-03-26T15:40:54.810891Z","shell.execute_reply":"2022-03-26T15:40:54.811433Z","shell.execute_reply.started":"2022-03-25T21:16:24.045346Z"},"papermill":{"duration":0.615164,"end_time":"2022-03-26T15:40:54.811609","exception":false,"start_time":"2022-03-26T15:40:54.196445","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#pd.pivot_table(index='CabinSide', data=train_df, values='Transported', aggfunc=['count', 'sum', 'mean'])\n_pivot_1 = pd.pivot_table(index=['CryoSleep', 'HomePlanet', 'CabinDeck'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_2 = pd.pivot_table(index=['CabinDeck'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_3 = pd.pivot_table(index=['CabinSide', 'CabinDeck'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_4 = pd.pivot_table(index=['CabinSide', 'HomePlanet'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_5 = pd.pivot_table(index=['HomePlanet', 'CabinDeck'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n\n_ = pd.pivot_table(index=['CryoSleep', 'HomePlanet', 'CabinDeck'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].reset_index()\n\n_val = _[_['CryoSleep'] == True].sort_values(by='CabinDeck')['Transported'].values - _[_['CryoSleep'] == False].sort_values(by='CabinDeck').iloc[:-1]['Transported'].values\n_df = _[_['CryoSleep'] == True].sort_values(by='CabinDeck')\n_df['Diff'] = _val\n_df = _df[['HomePlanet', 'CabinDeck', 'Diff']].sort_values(by='Diff', ascending=False).style.background_gradient(cmap='BuPu')\n\nmulti_table([_pivot_1,_pivot_2,_pivot_3,_pivot_4,_pivot_5, _df])","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:54.946064Z","iopub.status.busy":"2022-03-26T15:40:54.944281Z","iopub.status.idle":"2022-03-26T15:40:55.07241Z","shell.execute_reply":"2022-03-26T15:40:55.071791Z","shell.execute_reply.started":"2022-03-25T21:16:24.585043Z"},"papermill":{"duration":0.195526,"end_time":"2022-03-26T15:40:55.07255","exception":false,"start_time":"2022-03-26T15:40:54.877024","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.5\"></a>\n### **<span style=\"color:#7A5197;\">4.5 Destination</span>**\n* `55 Cancri-e` is optimal probablility to be transported than other.\n* `TRAPPIST-1e & Earth`: 0.38 probability to be transported.\n* if `CryoSleep` option include, this given more probability to be transported.","metadata":{"papermill":{"duration":0.064021,"end_time":"2022-03-26T15:40:55.203183","exception":false,"start_time":"2022-03-26T15:40:55.139162","status":"completed"},"tags":[]}},{"cell_type":"code","source":"_pivot_1 = pd.pivot_table(index=['Destination'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_2 = pd.pivot_table(index=['Destination'], columns=['HomePlanet'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu', axis=0)\n_pivot_3 = pd.pivot_table(index=['Destination', 'CryoSleep'], columns=['HomePlanet'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_4 = pd.pivot_table(index=['Destination', 'CabinDeck'], columns=['HomePlanet'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n\nmulti_table([_pivot_1, _pivot_2, _pivot_3, _pivot_4])","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:55.343363Z","iopub.status.busy":"2022-03-26T15:40:55.342626Z","iopub.status.idle":"2022-03-26T15:40:55.433481Z","shell.execute_reply":"2022-03-26T15:40:55.434149Z","shell.execute_reply.started":"2022-03-25T21:16:24.706878Z"},"papermill":{"duration":0.165354,"end_time":"2022-03-26T15:40:55.43434","exception":false,"start_time":"2022-03-26T15:40:55.268986","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.6\"></a>\n### **<span style=\"color:#7A5197;\">4.6 Age</span>**\n\n* Age under 10 is `0.72` probablity to be transported.\n* Earthlings over 20 years old suffered the most.\n* Passengers in CabinDeck `e` and `f` over 20 years old suffered the most.\n","metadata":{"papermill":{"duration":0.065686,"end_time":"2022-03-26T15:40:55.565212","exception":false,"start_time":"2022-03-26T15:40:55.499526","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_df['AgeBins'] = pd.cut(train_df['Age'], bins=8, labels=['>10', '10-20', '20-30', '30-40', '40-50', '50-60', '60-70', '70-80'])\n\nfacecolor = '#f6f5f5'\nfig = plt.figure(figsize=(16, 3), facecolor=facecolor)\ncolors_age = ['#2C0735', '#7A5197', '#BB5098', '#4E148C', '#613DC1', '#858AE3','#56CBF9', '#97DFFC', '#F7F4EA']\n\nfor i, t_val in enumerate(train_df.AgeBins.unique()):\n    ax = fig.add_subplot(1, 9, i+1, facecolor=facecolor)\n    _pivot_df = pd.pivot_table(train_df[train_df['AgeBins'] == t_val], index='HomePlanet', aggfunc='count', values='CryoSleep')\n    ax.barh(_pivot_df.index, _pivot_df['CryoSleep'], color=colors_age[:9][i])\n    #_target_col = {False: 'Without CryoSleep', True: 'CryoSleep'}\n    ax.set_title(t_val, fontsize=12, fontweight=\"medium\")\n    ax.tick_params(left=False, bottom=False, right=False, top=False, labelleft=(i<=1))\n    ax.xaxis.set_ticks([])\n\n    for _, spine in ax.spines.items():\n        spine.set_visible(False)\n        \n    if i != 0:\n        ax.yaxis.set_ticks([])\n    else:\n        pass\n    for ind, val in enumerate(_pivot_df['CryoSleep']):\n        #print(val)\n        ax.text(0, ind, formatter(val), fontweight=\"bold\", color=facecolor, fontsize=14)\n    \n\nfig.text(0.1, 1.2,'Bar Plot Count of Passengers',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.1, 1.08,'by Age',fontweight='bold', fontsize=24, color='#7A5197');\nfig.legend(train_df.AgeBins.unique(), ncol=8, facecolor='#f6f5f5', edgecolor='#f6f5f5',loc='lower center', fontsize=8, framealpha=1)\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:55.699015Z","iopub.status.busy":"2022-03-26T15:40:55.698313Z","iopub.status.idle":"2022-03-26T15:40:56.44349Z","shell.execute_reply":"2022-03-26T15:40:56.444039Z","shell.execute_reply.started":"2022-03-25T21:16:24.802893Z"},"papermill":{"duration":0.81404,"end_time":"2022-03-26T15:40:56.444221","exception":false,"start_time":"2022-03-26T15:40:55.630181","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_pivot_1 = pd.pivot_table(index=['AgeBins'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_2 = pd.pivot_table(index=['HomePlanet', 'AgeBins'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_3 = pd.pivot_table(index=['AgeBins', 'HomePlanet'], columns=['Destination'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu', axis=0)\n_pivot_4 = pd.pivot_table(index=['AgeBins'], columns=['CabinDeck'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu', axis=0)\n\nmulti_table([_pivot_1, _pivot_2, _pivot_3, _pivot_4])\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:56.595572Z","iopub.status.busy":"2022-03-26T15:40:56.594889Z","iopub.status.idle":"2022-03-26T15:40:56.695928Z","shell.execute_reply":"2022-03-26T15:40:56.696437Z","shell.execute_reply.started":"2022-03-25T21:16:25.468176Z"},"papermill":{"duration":0.182258,"end_time":"2022-03-26T15:40:56.69661","exception":false,"start_time":"2022-03-26T15:40:56.514352","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(9, 5), facecolor=facecolor)\ncolors = ['#5344A9', '#7A5197', '#BB5098', '#F5C63C', '#F47F6B']\ncolors_dark = ['#382F6C', '#563C68', '#864670', '#F5C63C', '#F47F6B']\n\n\ndef formatter(v):\n    if type(v) is str:\n        return v\n    if pd.isna(v) or v <= 0:\n        return ''\n    if v == int(v):\n        return f'{v:.0f}'\n    return f'{v:.1f}'\n\n\nfor i, t_val in enumerate(train_df.HomePlanet.unique()):\n    ax = fig.add_subplot(1, 3, i+1, facecolor=facecolor)\n    _pivot_df = pd.pivot_table(train_df[train_df['HomePlanet'] == t_val], columns=['CryoSleep'], index='AgeBins', aggfunc='mean', values='Transported')\n\n    ax.barh(_pivot_df.index, _pivot_df[True], color=colors[i])\n    ax.barh(_pivot_df.index, _pivot_df[False], color=colors_dark[i])\n\n    _target_col = {False: 'Without CryoSleep', True: 'CryoSleep'}\n    ax.set_title(f'{t_val}', fontsize=12, fontweight=\"medium\")\n    ax.tick_params(left=False, bottom=False, right=False, top=False, labelleft=(i<=1))\n    ax.xaxis.set_ticks([])\n    plt.legend(['CryoSleep', 'Without CryoSleep'], ncol=1, facecolor='#f6f5f5', edgecolor='#f6f5f5', loc='lower center', fontsize=8, framealpha=1)\n\n    for _, spine in ax.spines.items():\n        spine.set_visible(False)\n        \n    if i != 0:\n        ax.yaxis.set_ticks([])\n    else:\n        pass\n    for ind, val in enumerate(_pivot_df[False]):\n        #print(val)\n        ax.text(0, ind, formatter(val), fontweight=\"bold\", color=facecolor, fontsize=14)\n        \nfig.text(0.1, 1.16,'Bar Plot Probability of Being Transported',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.1, 1.08,'by HomePlanet & Age',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.1, 1,'With Option CryoSleep ',fontweight='bold', fontsize=24, color='#7A5197');\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:56.84245Z","iopub.status.busy":"2022-03-26T15:40:56.841778Z","iopub.status.idle":"2022-03-26T15:40:57.343757Z","shell.execute_reply":"2022-03-26T15:40:57.344515Z","shell.execute_reply.started":"2022-03-25T21:16:25.579342Z"},"papermill":{"duration":0.576777,"end_time":"2022-03-26T15:40:57.344811","exception":false,"start_time":"2022-03-26T15:40:56.768034","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(9, 5), facecolor=facecolor)\ncolors = ['#5344A9', '#7A5197', '#BB5098', '#F47F6B', '#F5C63C']\ncolors_dark = ['#382F6C', '#563C68', '#864670', '#C46D5E','#B89631']\n\n\ndef formatter(v):\n    if type(v) is str:\n        return v\n    if pd.isna(v) or v <= 0:\n        return ''\n    if v == int(v):\n        return f'{v:.0f}'\n    return f'{v:.1f}'\n\n\nfor i, t_val in enumerate(train_df.Destination.unique()):\n    ax = fig.add_subplot(1, 3, i+1, facecolor=facecolor)\n    _pivot_df = pd.pivot_table(train_df[train_df['Destination'] == t_val], columns=['CryoSleep'], index='AgeBins', aggfunc='mean', values='Transported')\n\n    ax.barh(_pivot_df.index, _pivot_df[True], color=colors[::-1][i])\n    ax.barh(_pivot_df.index, _pivot_df[False], color=colors_dark[::-1][i])\n\n    _target_col = {False: 'Without CryoSleep', True: 'CryoSleep'}\n    ax.set_title(f'{t_val}', fontsize=12, fontweight=\"medium\")\n    ax.tick_params(left=False, bottom=False, right=False, top=False, labelleft=(i<=1))\n    ax.xaxis.set_ticks([])\n    plt.legend(['CryoSleep', 'Without CryoSleep'], ncol=1, facecolor='#f6f5f5', edgecolor='#f6f5f5', loc='lower center', fontsize=8, framealpha=1)\n\n    for _, spine in ax.spines.items():\n        spine.set_visible(False)\n        \n    if i != 0:\n        ax.yaxis.set_ticks([])\n    else:\n        pass\n    for ind, val in enumerate(_pivot_df[False]):\n        #print(val)\n        ax.text(0, ind, formatter(val), fontweight=\"bold\", color=facecolor, fontsize=14)\n        \nfig.text(0.1, 1.16,'Bar Plot Probability of Being Transported',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.1, 1.08,'by Destination & Age',fontweight='bold', fontsize=24, color='#7A5197');\nfig.text(0.1, 1,'With Option CryoSleep ',fontweight='bold', fontsize=24, color='#7A5197');\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:57.527324Z","iopub.status.busy":"2022-03-26T15:40:57.526298Z","iopub.status.idle":"2022-03-26T15:40:58.050089Z","shell.execute_reply":"2022-03-26T15:40:58.049437Z","shell.execute_reply.started":"2022-03-25T21:16:26.020625Z"},"papermill":{"duration":0.605366,"end_time":"2022-03-26T15:40:58.050243","exception":false,"start_time":"2022-03-26T15:40:57.444877","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.7\"></a>\n### **<span style=\"color:#7A5197;\">4.7 Vip</span>**\n\n* `VIP` status does not affect transported chance","metadata":{"papermill":{"duration":0.073259,"end_time":"2022-03-26T15:40:58.200673","exception":false,"start_time":"2022-03-26T15:40:58.127414","status":"completed"},"tags":[]}},{"cell_type":"code","source":"plt.subplots(figsize=(25, 10), facecolor='#f6f5f5')\nplt.pie(train_df.VIP.value_counts(), startangle=90, wedgeprops={'width':0.3}, colors=[colors[3], '#f6f5f5'] )\nplt.title('VIP Balance Pie Chart', loc='center', fontsize=24, color=colors[3], fontweight='bold')\nplt.text(0, 0, f\"{train_df.VIP.value_counts()[0] / train_df.VIP.count() * 100:.2f}%\", ha='center', va='center', fontweight='bold',  fontsize=42, color=colors[3])\n#plt.legend(['True', ''], ncol=2, facecolor='#f6f5f5', edgecolor='#f6f5f5', loc='lower center', fontsize=16)\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:58.357073Z","iopub.status.busy":"2022-03-26T15:40:58.356401Z","iopub.status.idle":"2022-03-26T15:40:58.531382Z","shell.execute_reply":"2022-03-26T15:40:58.532318Z","shell.execute_reply.started":"2022-03-25T21:16:26.457462Z"},"papermill":{"duration":0.254568,"end_time":"2022-03-26T15:40:58.532625","exception":false,"start_time":"2022-03-26T15:40:58.278057","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_pivot_1 = pd.pivot_table(index=['VIP'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_2 = pd.pivot_table(index=['VIP', 'HomePlanet'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu')\n_pivot_3 = pd.pivot_table(index=['VIP', 'HomePlanet'], columns=['Destination'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu', axis=0)\n_pivot_4 = pd.pivot_table(index=['VIP'], columns=['CabinDeck'], data=train_df, values='Transported', aggfunc=['mean'])['mean'].style.background_gradient(cmap='BuPu', axis=1)\n\nmulti_table([_pivot_1, _pivot_2, _pivot_3, _pivot_4])","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:58.711274Z","iopub.status.busy":"2022-03-26T15:40:58.710615Z","iopub.status.idle":"2022-03-26T15:40:58.801534Z","shell.execute_reply":"2022-03-26T15:40:58.800997Z","shell.execute_reply.started":"2022-03-25T21:16:26.597042Z"},"papermill":{"duration":0.168648,"end_time":"2022-03-26T15:40:58.801688","exception":false,"start_time":"2022-03-26T15:40:58.63304","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.8\"></a>\n### **<span style=\"color:#7A5197;\">4.8 RoomService</span>**\n* RoomService option is popular for residers of `Mars` and `Europe` and whose destination of `Trappist` and `Canci`. \n* `VIP` passengers is also used this option more than other.\n* `Young` passengers more used this option then older.","metadata":{"papermill":{"duration":0.076524,"end_time":"2022-03-26T15:40:58.95499","exception":false,"start_time":"2022-03-26T15:40:58.878466","status":"completed"},"tags":[]}},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(14, 8), facecolor=facecolor)\ngs = fig.add_gridspec(2, 1)\n\ngs.update(wspace=0.2, hspace=0.7)\n\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[1, 0])\n\nax0.set_facecolor(facecolor)\nfor s in [\"top\",\"right\", \"left\", \"bottom\"]:\n    ax0.spines[s].set_visible(False)\n\nax1.set_facecolor(facecolor)\nfor s in [\"top\",\"right\",\"left\", \"bottom\"]:\n    ax1.spines[s].set_visible(False)\n    \nsns.violinplot(x=\"HomePlanet\", y=\"RoomService\", data=train_df, hue='Destination', ax=ax0, color=colors[3])\nsns.violinplot(x=\"AgeBins\", y=\"RoomService\", data=train_df, hue='VIP', split=True, ax=ax1, color=colors[1])\n\nax0.legend(ncol=3, facecolor=facecolor, edgecolor=facecolor, loc='upper center')\nax0.text(-0.6, 15000, 'RoomService Distributions', fontweight='bold', fontsize=24, color=colors[3]);\nax0.text(-0.6, 13000, 'by Destination & HomePlanet', fontweight='bold', fontsize=24, color=colors[3]);\n\nax1.legend(ncol=2, facecolor=facecolor, edgecolor=facecolor, loc='upper center');\nax1.text(-0.7, 14000, 'RoomService Distributions', fontweight='bold', fontsize=24, color=colors[1]);\nax1.text(-0.7, 12000, 'by VIP & Age', fontweight='bold', fontsize=24, color=colors[1]);\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:40:59.112224Z","iopub.status.busy":"2022-03-26T15:40:59.111515Z","iopub.status.idle":"2022-03-26T15:41:00.302607Z","shell.execute_reply":"2022-03-26T15:41:00.303163Z","shell.execute_reply.started":"2022-03-25T21:16:26.684973Z"},"papermill":{"duration":1.270979,"end_time":"2022-03-26T15:41:00.303344","exception":false,"start_time":"2022-03-26T15:40:59.032365","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.9\"></a>\n### **<span style=\"color:#7A5197;\">4.9 FoodCourt</span>**\n* FoodCourt preferred residents `Europe`.\n* `VIP` passengers is also preffered this option.\n* Passengers whose years between`30-50` preffered FooCourt more then other.","metadata":{"papermill":{"duration":0.079592,"end_time":"2022-03-26T15:41:00.463418","exception":false,"start_time":"2022-03-26T15:41:00.383826","status":"completed"},"tags":[]}},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(14, 8), facecolor=facecolor)\ngs = fig.add_gridspec(2, 1)\n\ngs.update(wspace=0.2, hspace=0.7)\n\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[1, 0])\n\nax0.set_facecolor(facecolor)\nfor s in [\"top\",\"right\", \"left\", \"bottom\"]:\n    ax0.spines[s].set_visible(False)\n\nax1.set_facecolor(facecolor)\nfor s in [\"top\",\"right\",\"left\", \"bottom\"]:\n    ax1.spines[s].set_visible(False)\n    \nsns.violinplot(x=\"HomePlanet\", y=\"FoodCourt\", data=train_df, hue='Destination', ax=ax0, color=colors[3])\nsns.violinplot(x=\"AgeBins\", y=\"FoodCourt\", data=train_df, hue='VIP', split=True, ax=ax1, color=colors[1])\n\nax0.legend(ncol=3, facecolor=facecolor, edgecolor=facecolor, loc='upper center')\nax0.text(-0.6, 50000, 'FoodCourt Distributions', fontweight='bold', fontsize=24, color=colors[3]);\nax0.text(-0.6, 44000, 'by Destination & HomePlanet', fontweight='bold', fontsize=24, color=colors[3]);\n\nax1.legend(ncol=2, facecolor=facecolor, edgecolor=facecolor, loc='upper center');\nax1.text(-0.6, 54000, 'FoodCourt Distributions', fontweight='bold', fontsize=24, color=colors[1]);\nax1.text(-0.6, 46000, 'by VIP & Age', fontweight='bold', fontsize=24, color=colors[1]);\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:41:00.632409Z","iopub.status.busy":"2022-03-26T15:41:00.631361Z","iopub.status.idle":"2022-03-26T15:41:01.761237Z","shell.execute_reply":"2022-03-26T15:41:01.761758Z","shell.execute_reply.started":"2022-03-25T21:16:27.797613Z"},"papermill":{"duration":1.218124,"end_time":"2022-03-26T15:41:01.761929","exception":false,"start_time":"2022-03-26T15:41:00.543805","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.10\"></a>\n### **<span style=\"color:#7A5197;\">4.10 ShoppingMall</span>**\n* ShoppingMall preferred residents `Europe` and whose destination to `Trappist` and `Cancri`.\n* Passengers whose years between`10-50` preffered ShoppingMall more then other.","metadata":{"papermill":{"duration":0.082875,"end_time":"2022-03-26T15:41:01.930441","exception":false,"start_time":"2022-03-26T15:41:01.847566","status":"completed"},"tags":[]}},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(14, 8), facecolor=facecolor)\ngs = fig.add_gridspec(2, 1)\n\ngs.update(wspace=0.2, hspace=0.7)\n\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[1, 0])\n\nax0.set_facecolor(facecolor)\nfor s in [\"top\",\"right\", \"left\", \"bottom\"]:\n    ax0.spines[s].set_visible(False)\n\nax1.set_facecolor(facecolor)\nfor s in [\"top\",\"right\",\"left\", \"bottom\"]:\n    ax1.spines[s].set_visible(False)\n    \nsns.violinplot(x=\"HomePlanet\", y=\"ShoppingMall\", data=train_df, hue='Destination', ax=ax0, color=colors[3])\nsns.violinplot(x=\"AgeBins\", y=\"ShoppingMall\", data=train_df, hue='VIP', split=True, ax=ax1, color=colors[1])\n\nax0.legend(ncol=3, facecolor=facecolor, edgecolor=facecolor, loc='upper center')\nax0.text(-0.6, 18000, 'ShoppingMall Distributions', fontweight='bold', fontsize=24, color=colors[3]);\nax0.text(-0.6, 15000, 'by Destination & HomePlanet', fontweight='bold', fontsize=24, color=colors[3]);\n\nax1.legend(ncol=2, facecolor=facecolor, edgecolor=facecolor, loc='upper center');\nax1.text(-0.6, 18000, 'ShoppingMall Distributions', fontweight='bold', fontsize=24, color=colors[1]);\nax1.text(-0.6, 15000, 'by VIP & Age', fontweight='bold', fontsize=24, color=colors[1]);\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:41:02.104317Z","iopub.status.busy":"2022-03-26T15:41:02.103244Z","iopub.status.idle":"2022-03-26T15:41:03.332257Z","shell.execute_reply":"2022-03-26T15:41:03.332812Z","shell.execute_reply.started":"2022-03-25T21:16:28.839714Z"},"papermill":{"duration":1.320079,"end_time":"2022-03-26T15:41:03.332994","exception":false,"start_time":"2022-03-26T15:41:02.012915","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.11\"></a>\n### **<span style=\"color:#7A5197;\">4.11 Spa</span>**\n* SPA preferred residents `Europe`.\n* SPA preferred also whose older and age more than `30`.\n","metadata":{"papermill":{"duration":0.10038,"end_time":"2022-03-26T15:41:03.526518","exception":false,"start_time":"2022-03-26T15:41:03.426138","status":"completed"},"tags":[]}},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(14, 8), facecolor=facecolor)\ngs = fig.add_gridspec(2, 1)\n\ngs.update(wspace=0.2, hspace=0.7)\n\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[1, 0])\n\nax0.set_facecolor(facecolor)\nfor s in [\"top\",\"right\", \"left\", \"bottom\"]:\n    ax0.spines[s].set_visible(False)\n\nax1.set_facecolor(facecolor)\nfor s in [\"top\",\"right\",\"left\", \"bottom\"]:\n    ax1.spines[s].set_visible(False)\n    \nsns.violinplot(x=\"HomePlanet\", y=\"Spa\", data=train_df, hue='Destination', ax=ax0, color=colors[3])\nsns.violinplot(x=\"AgeBins\", y=\"Spa\", data=train_df, hue='VIP', split=True, ax=ax1, color=colors[1])\n\nax0.legend(ncol=3, facecolor=facecolor, edgecolor=facecolor, loc='upper center')\nax0.text(-0.6, 33000, 'Spa Distributions', fontweight='bold', fontsize=24, color=colors[3]);\nax0.text(-0.6, 28000, 'by Destination & HomePlanet', fontweight='bold', fontsize=24, color=colors[3]);\n\nax1.legend(ncol=2, facecolor=facecolor, edgecolor=facecolor, loc='upper center');\nax1.text(-0.6, 33000, 'Spa Distributions', fontweight='bold', fontsize=24, color=colors[1]);\nax1.text(-0.6, 28000, 'by VIP & Age', fontweight='bold', fontsize=24, color=colors[1]);\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:41:03.721843Z","iopub.status.busy":"2022-03-26T15:41:03.716351Z","iopub.status.idle":"2022-03-26T15:41:05.044302Z","shell.execute_reply":"2022-03-26T15:41:05.0436Z","shell.execute_reply.started":"2022-03-25T21:16:29.945107Z"},"papermill":{"duration":1.42217,"end_time":"2022-03-26T15:41:05.044443","exception":false,"start_time":"2022-03-26T15:41:03.622273","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[back to top](#table-of-contents)\n<a id=\"4.12\"></a>\n### **<span style=\"color:#7A5197;\">4.12 VRDeck</span>**\n* VRDeck preferred also whose `young` and without `VIP`.\n* VRDeck preferred `VIP` passengers whose age more then `30`.\n* Target audience is `VIP` passengers ~ 45 years old.\n","metadata":{"papermill":{"duration":0.087858,"end_time":"2022-03-26T15:41:05.222629","exception":false,"start_time":"2022-03-26T15:41:05.134771","status":"completed"},"tags":[]}},{"cell_type":"code","source":"facecolor = '#f6f5f5'\nfig = plt.figure(figsize=(14, 8), facecolor=facecolor)\ngs = fig.add_gridspec(2, 1)\n\ngs.update(wspace=0.2, hspace=0.7)\n\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[1, 0])\n\nax0.set_facecolor(facecolor)\nfor s in [\"top\",\"right\", \"left\", \"bottom\"]:\n    ax0.spines[s].set_visible(False)\n\nax1.set_facecolor(facecolor)\nfor s in [\"top\",\"right\",\"left\", \"bottom\"]:\n    ax1.spines[s].set_visible(False)\n    \nsns.violinplot(x=\"HomePlanet\", y=\"VRDeck\", data=train_df, hue='Destination', ax=ax0, color=colors[3])\nsns.violinplot(x=\"AgeBins\", y=\"VRDeck\", data=train_df, hue='VIP', split=True, ax=ax1, color=colors[1])\n\nax0.legend(ncol=3, facecolor=facecolor, edgecolor=facecolor, loc='upper center')\nax0.text(-0.6, 31000, 'VRDeck Distributions', fontweight='bold', fontsize=24, color=colors[3]);\nax0.text(-0.6, 26000, 'by Destination & HomePlanet', fontweight='bold', fontsize=24, color=colors[3]);\n\nax1.legend(ncol=2, facecolor=facecolor, edgecolor=facecolor, loc='upper center');\nax1.text(-0.7, 31000, 'VRDeck Distributions', fontweight='bold', fontsize=24, color=colors[1]);\nax1.text(-0.7, 26000, 'by VIP & Age', fontweight='bold', fontsize=24, color=colors[1]);\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:41:05.404865Z","iopub.status.busy":"2022-03-26T15:41:05.398893Z","iopub.status.idle":"2022-03-26T15:41:06.492906Z","shell.execute_reply":"2022-03-26T15:41:06.493414Z","shell.execute_reply.started":"2022-03-25T21:16:31.152097Z"},"papermill":{"duration":1.184376,"end_time":"2022-03-26T15:41:06.493583","exception":false,"start_time":"2022-03-26T15:41:05.309207","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(10, 13), facecolor=facecolor)\nax = fig.add_subplot(111, projection='3d')\nax.scatter(train_df['RoomService'], train_df['FoodCourt'], train_df['ShoppingMall'], color=colors[0])\nax.view_init(25, 45)\nax.set_facecolor(facecolor)\nax.set_xlabel('RoomService')\nax.set_ylabel('FoodCourt')\nax.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))\nax.yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))\nax.zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))\nax.xaxis._axinfo['grid']['color'] = (1, 1, 1, 0)\nax.yaxis._axinfo['grid']['color'] = (1, 1, 1, 0)\nax.zaxis._axinfo['grid']['color'] = (1, 1, 1, 0)\nax.w_zaxis.line.set_lw(0.)\nax.set_zticks([]);\nfig.text(0.15, 0.8, '3d Scatter of included options', fontweight='bold', fontsize=24, color=colors[1]);\nfig.text(0.15, 0.77, 'RoomService & FoodCourt & ShoppingMall', fontweight='bold', fontsize=18, color=colors[1]);\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.execute_input":"2022-03-26T15:41:06.691334Z","iopub.status.busy":"2022-03-26T15:41:06.68258Z","iopub.status.idle":"2022-03-26T15:41:07.162479Z","shell.execute_reply":"2022-03-26T15:41:07.163019Z","shell.execute_reply.started":"2022-03-25T21:16:32.179136Z"},"papermill":{"duration":0.578854,"end_time":"2022-03-26T15:41:07.163495","exception":false,"start_time":"2022-03-26T15:41:06.584641","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"5\"></a>\n# **<span style=\"color:#7A5197;\">5 Reference</span>**\n\n* [multitables](https://www.kaggle.com/code/arootda/pycaret-visualization-optimization-0-81#%F0%9F%93%8C-Import-Modules)  \n* [visualition](https://www.kaggle.com/code/jtrotman/f1-race-traces-2007#More-F1-Race-Traces)  \n* [visualition](https://www.kaggle.com/code/dwin183287/tps-june-2021-eda)  ","metadata":{"papermill":{"duration":0.099525,"end_time":"2022-03-26T15:41:07.363005","exception":false,"start_time":"2022-03-26T15:41:07.26348","status":"completed"},"tags":[]}}]}