{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-09T14:26:35.597952Z","iopub.execute_input":"2022-07-09T14:26:35.598491Z","iopub.status.idle":"2022-07-09T14:26:36.413322Z","shell.execute_reply.started":"2022-07-09T14:26:35.598448Z","shell.execute_reply":"2022-07-09T14:26:36.411999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/spaceship-titanic/train.csv\")\ntest_df = pd.read_csv(\"/kaggle/input/spaceship-titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:26:38.601287Z","iopub.execute_input":"2022-07-09T14:26:38.601779Z","iopub.status.idle":"2022-07-09T14:26:38.662715Z","shell.execute_reply.started":"2022-07-09T14:26:38.601743Z","shell.execute_reply":"2022-07-09T14:26:38.661736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head(20)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:26:38.989395Z","iopub.execute_input":"2022-07-09T14:26:38.990740Z","iopub.status.idle":"2022-07-09T14:26:39.035477Z","shell.execute_reply.started":"2022-07-09T14:26:38.990669Z","shell.execute_reply":"2022-07-09T14:26:39.033976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## EDA","metadata":{}},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:28:13.557616Z","iopub.execute_input":"2022-07-09T14:28:13.558144Z","iopub.status.idle":"2022-07-09T14:28:13.579027Z","shell.execute_reply.started":"2022-07-09T14:28:13.558100Z","shell.execute_reply":"2022-07-09T14:28:13.577884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\n\nax = sns.countplot(x ='HomePlanet', hue = 'Transported', data = train_df)\nfor i in ax.containers:\n    ax.bar_label(i,)\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:26:40.381220Z","iopub.execute_input":"2022-07-09T14:26:40.381761Z","iopub.status.idle":"2022-07-09T14:26:40.687557Z","shell.execute_reply.started":"2022-07-09T14:26:40.381718Z","shell.execute_reply":"2022-07-09T14:26:40.686376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\n\nax = sns.countplot(x ='CryoSleep', hue = 'Transported', data = train_df)\nfor i in ax.containers:\n    ax.bar_label(i,)\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:26:51.422210Z","iopub.execute_input":"2022-07-09T14:26:51.422705Z","iopub.status.idle":"2022-07-09T14:26:51.632295Z","shell.execute_reply.started":"2022-07-09T14:26:51.422665Z","shell.execute_reply":"2022-07-09T14:26:51.630948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\n\nax = sns.countplot(x ='Destination', hue = 'Transported', data = train_df)\nfor i in ax.containers:\n    ax.bar_label(i,)\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:26:58.455342Z","iopub.execute_input":"2022-07-09T14:26:58.455828Z","iopub.status.idle":"2022-07-09T14:26:58.668653Z","shell.execute_reply.started":"2022-07-09T14:26:58.455790Z","shell.execute_reply":"2022-07-09T14:26:58.667413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\n\nax = sns.countplot(x ='VIP', hue = 'Transported', data = train_df)\nfor i in ax.containers:\n    ax.bar_label(i,)\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:04.904475Z","iopub.execute_input":"2022-07-09T14:27:04.905666Z","iopub.status.idle":"2022-07-09T14:27:05.117143Z","shell.execute_reply.started":"2022-07-09T14:27:04.905619Z","shell.execute_reply":"2022-07-09T14:27:05.115759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bins = [0, 1, 5, 10, 25, 50, 100]\nlabels = ['0-1','1-5','5-10','10-25','25-50','50-100']\n\ndf_copy = train_df.copy()\ndf_copy['age_distribuition'] = pd.cut(train_df['Age'], bins=bins, labels=labels)\n\nplt.figure(figsize=(15,5))\n\nax = sns.countplot(x ='age_distribuition', hue = 'Transported', data = df_copy)\n\nfor i in ax.containers:\n    ax.bar_label(i,)\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:11.956460Z","iopub.execute_input":"2022-07-09T14:27:11.956908Z","iopub.status.idle":"2022-07-09T14:27:12.229064Z","shell.execute_reply.started":"2022-07-09T14:27:11.956874Z","shell.execute_reply":"2022-07-09T14:27:12.227613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['RoomService'].max(axis= 0)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:24.364587Z","iopub.execute_input":"2022-07-09T14:27:24.365056Z","iopub.status.idle":"2022-07-09T14:27:24.373998Z","shell.execute_reply.started":"2022-07-09T14:27:24.365003Z","shell.execute_reply":"2022-07-09T14:27:24.373094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['FoodCourt'].max(axis= 0)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:25.527291Z","iopub.execute_input":"2022-07-09T14:27:25.528196Z","iopub.status.idle":"2022-07-09T14:27:25.537494Z","shell.execute_reply.started":"2022-07-09T14:27:25.528138Z","shell.execute_reply":"2022-07-09T14:27:25.536106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['ShoppingMall'].max(axis= 0)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:32.120853Z","iopub.execute_input":"2022-07-09T14:27:32.121304Z","iopub.status.idle":"2022-07-09T14:27:32.131121Z","shell.execute_reply.started":"2022-07-09T14:27:32.121266Z","shell.execute_reply":"2022-07-09T14:27:32.129810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Spa'].max(axis= 0)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:37.666404Z","iopub.execute_input":"2022-07-09T14:27:37.667749Z","iopub.status.idle":"2022-07-09T14:27:37.676606Z","shell.execute_reply.started":"2022-07-09T14:27:37.667697Z","shell.execute_reply":"2022-07-09T14:27:37.675724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['VRDeck'].max(axis= 0)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:43.429244Z","iopub.execute_input":"2022-07-09T14:27:43.429729Z","iopub.status.idle":"2022-07-09T14:27:43.439171Z","shell.execute_reply.started":"2022-07-09T14:27:43.429689Z","shell.execute_reply":"2022-07-09T14:27:43.438004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def make_bins(value):\n    value_increment = 5000\n    total_bins = int(value/value_increment)\n    \n    bins_list = []\n    inital_value = 0\n    \n    for i in range(0, total_bins+2):\n        bins_list.append(inital_value)\n        inital_value += value_increment\n        \n    return bins_list","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:48.794713Z","iopub.execute_input":"2022-07-09T14:27:48.795220Z","iopub.status.idle":"2022-07-09T14:27:48.802331Z","shell.execute_reply.started":"2022-07-09T14:27:48.795178Z","shell.execute_reply":"2022-07-09T14:27:48.801041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_name_list = [\"RoomService\", 'FoodCourt', 'ShoppingMall', 'Spa', 'VRDeck']\nfor column_name in column_name_list:\n    bins = make_bins(train_df[column_name].max(axis= 0))\n\n    df_copy = train_df.copy()\n    df_copy[f'{column_name}_distribution'] = pd.cut(train_df[column_name], bins=bins)\n\n    plt.figure(figsize=(25,7))\n\n    ax = sns.countplot(x =f'{column_name}_distribution', hue = 'Transported', data = df_copy)\n\n    for i in ax.containers:\n        ax.bar_label(i,)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:27:55.680290Z","iopub.execute_input":"2022-07-09T14:27:55.680726Z","iopub.status.idle":"2022-07-09T14:27:57.008696Z","shell.execute_reply.started":"2022-07-09T14:27:55.680692Z","shell.execute_reply":"2022-07-09T14:27:57.007440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Cabin'].fillna(\"Not_Found\", inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:28:23.295442Z","iopub.execute_input":"2022-07-09T14:28:23.295899Z","iopub.status.idle":"2022-07-09T14:28:23.303849Z","shell.execute_reply.started":"2022-07-09T14:28:23.295862Z","shell.execute_reply":"2022-07-09T14:28:23.302828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_deck = []\ncabin_num = []\ncabin_port = []\n\nfor deck in train_df['Cabin']:\n    if deck != 'Not_Found':\n        list_of_deck = deck.split(\"/\")\n        cabin_deck.append(list_of_deck[0])\n        cabin_num.append(int(list_of_deck[1]))\n        cabin_port.append(list_of_deck[2])\n    else:\n        cabin_deck.append(\"Not_Found\")\n        cabin_num.append(\"Not_Found\")\n        cabin_port.append(\"Not_Found\")\n\ntrain_df['Cabin_deck'] = cabin_deck\ntrain_df['Cabin_num'] = cabin_num\ntrain_df['Cabin_port'] = cabin_port","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:28:29.501796Z","iopub.execute_input":"2022-07-09T14:28:29.503103Z","iopub.status.idle":"2022-07-09T14:28:29.525627Z","shell.execute_reply.started":"2022-07-09T14:28:29.503037Z","shell.execute_reply":"2022-07-09T14:28:29.524400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\n\nax = sns.countplot(x ='Cabin_deck', hue = 'Transported', data = train_df)\nfor i in ax.containers:\n    ax.bar_label(i,)\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:28:36.785504Z","iopub.execute_input":"2022-07-09T14:28:36.785979Z","iopub.status.idle":"2022-07-09T14:28:37.165626Z","shell.execute_reply.started":"2022-07-09T14:28:36.785939Z","shell.execute_reply":"2022-07-09T14:28:37.164102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\n\nax = sns.countplot(x ='Cabin_port', hue = 'Transported', data = train_df)\nfor i in ax.containers:\n    ax.bar_label(i,)\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:28:44.413333Z","iopub.execute_input":"2022-07-09T14:28:44.413844Z","iopub.status.idle":"2022-07-09T14:28:44.655078Z","shell.execute_reply.started":"2022-07-09T14:28:44.413803Z","shell.execute_reply":"2022-07-09T14:28:44.653868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"passenger_group= []\npassenger_num = []\n\nfor passenger in train_df['PassengerId']:\n    if passenger != 'Not_Found':\n        list_of_passenger = passenger.split(\"_\")\n        passenger_group.append(list_of_passenger[0])\n        passenger_num.append(list_of_passenger[1])\n    else:\n        passenger_group.append(\"Not_Found\")\n        passenger_num.append(\"Not_Found\")\n\ntrain_df['Passenger_group'] = passenger_group\ntrain_df['Passenger_num'] = passenger_num","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:28:53.428230Z","iopub.execute_input":"2022-07-09T14:28:53.428747Z","iopub.status.idle":"2022-07-09T14:28:53.447620Z","shell.execute_reply.started":"2022-07-09T14:28:53.428708Z","shell.execute_reply":"2022-07-09T14:28:53.446066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T14:28:59.644926Z","iopub.execute_input":"2022-07-09T14:28:59.645398Z","iopub.status.idle":"2022-07-09T14:28:59.673184Z","shell.execute_reply.started":"2022-07-09T14:28:59.645359Z","shell.execute_reply":"2022-07-09T14:28:59.671864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"To be Continued....","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}