{"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)\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-08-09T11:50:41.187815Z","iopub.execute_input":"2022-08-09T11:50:41.188258Z","iopub.status.idle":"2022-08-09T11:50:41.199025Z","shell.execute_reply.started":"2022-08-09T11:50:41.188219Z","shell.execute_reply":"2022-08-09T11:50:41.197979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Importing the dataset","metadata":{}},{"cell_type":"code","source":"data = pd.read_csv('../input/titanic/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:43.377770Z","iopub.execute_input":"2022-08-09T11:50:43.378206Z","iopub.status.idle":"2022-08-09T11:50:43.388169Z","shell.execute_reply.started":"2022-08-09T11:50:43.378152Z","shell.execute_reply":"2022-08-09T11:50:43.387365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:44.322619Z","iopub.execute_input":"2022-08-09T11:50:44.323050Z","iopub.status.idle":"2022-08-09T11:50:44.341230Z","shell.execute_reply.started":"2022-08-09T11:50:44.323012Z","shell.execute_reply":"2022-08-09T11:50:44.340114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:45.242993Z","iopub.execute_input":"2022-08-09T11:50:45.243795Z","iopub.status.idle":"2022-08-09T11:50:45.251227Z","shell.execute_reply.started":"2022-08-09T11:50:45.243753Z","shell.execute_reply":"2022-08-09T11:50:45.249834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Imputing Missing value with mean/mode of variable","metadata":{}},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:46.767388Z","iopub.execute_input":"2022-08-09T11:50:46.767760Z","iopub.status.idle":"2022-08-09T11:50:46.776632Z","shell.execute_reply.started":"2022-08-09T11:50:46.767730Z","shell.execute_reply":"2022-08-09T11:50:46.775673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:47.837664Z","iopub.execute_input":"2022-08-09T11:50:47.838695Z","iopub.status.idle":"2022-08-09T11:50:47.847787Z","shell.execute_reply.started":"2022-08-09T11:50:47.838641Z","shell.execute_reply":"2022-08-09T11:50:47.846626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.Age.mean()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:48.627765Z","iopub.execute_input":"2022-08-09T11:50:48.628810Z","iopub.status.idle":"2022-08-09T11:50:48.636449Z","shell.execute_reply.started":"2022-08-09T11:50:48.628768Z","shell.execute_reply":"2022-08-09T11:50:48.635324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Age'] = data['Age'].fillna(30)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:49.532691Z","iopub.execute_input":"2022-08-09T11:50:49.533139Z","iopub.status.idle":"2022-08-09T11:50:49.539328Z","shell.execute_reply.started":"2022-08-09T11:50:49.533102Z","shell.execute_reply":"2022-08-09T11:50:49.538154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Cabin'].mode()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:50.462915Z","iopub.execute_input":"2022-08-09T11:50:50.463358Z","iopub.status.idle":"2022-08-09T11:50:50.471757Z","shell.execute_reply.started":"2022-08-09T11:50:50.463319Z","shell.execute_reply":"2022-08-09T11:50:50.470839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Cabin'] = data['Cabin'].fillna('B96')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:51.417724Z","iopub.execute_input":"2022-08-09T11:50:51.418440Z","iopub.status.idle":"2022-08-09T11:50:51.424845Z","shell.execute_reply.started":"2022-08-09T11:50:51.418403Z","shell.execute_reply":"2022-08-09T11:50:51.423447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Embarked'].mode()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:52.412624Z","iopub.execute_input":"2022-08-09T11:50:52.413122Z","iopub.status.idle":"2022-08-09T11:50:52.422622Z","shell.execute_reply.started":"2022-08-09T11:50:52.413082Z","shell.execute_reply":"2022-08-09T11:50:52.421504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Embarked'] = data.Embarked.fillna('S')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:53.332524Z","iopub.execute_input":"2022-08-09T11:50:53.333388Z","iopub.status.idle":"2022-08-09T11:50:53.339037Z","shell.execute_reply.started":"2022-08-09T11:50:53.333347Z","shell.execute_reply":"2022-08-09T11:50:53.338132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:54.202932Z","iopub.execute_input":"2022-08-09T11:50:54.204075Z","iopub.status.idle":"2022-08-09T11:50:54.214172Z","shell.execute_reply.started":"2022-08-09T11:50:54.204029Z","shell.execute_reply":"2022-08-09T11:50:54.213263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Sex'] = data.Sex.map({'male':1,'female':0})","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:54.997775Z","iopub.execute_input":"2022-08-09T11:50:54.998177Z","iopub.status.idle":"2022-08-09T11:50:55.005591Z","shell.execute_reply.started":"2022-08-09T11:50:54.998144Z","shell.execute_reply":"2022-08-09T11:50:55.004274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndata = pd.get_dummies(data,prefix='Embarked',prefix_sep='_',columns=['Embarked'])\n","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:56.112767Z","iopub.execute_input":"2022-08-09T11:50:56.113903Z","iopub.status.idle":"2022-08-09T11:50:56.124261Z","shell.execute_reply.started":"2022-08-09T11:50:56.113857Z","shell.execute_reply":"2022-08-09T11:50:56.123336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = data['Cabin'].value_counts()\ntemp = pd.DataFrame(temp)\ntemp.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:56.822854Z","iopub.execute_input":"2022-08-09T11:50:56.823922Z","iopub.status.idle":"2022-08-09T11:50:56.836529Z","shell.execute_reply.started":"2022-08-09T11:50:56.823855Z","shell.execute_reply":"2022-08-09T11:50:56.835342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp['Cabin_count'] = temp['Cabin']\ntemp['Cabin'] = temp.index","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:57.537373Z","iopub.execute_input":"2022-08-09T11:50:57.538448Z","iopub.status.idle":"2022-08-09T11:50:57.544306Z","shell.execute_reply.started":"2022-08-09T11:50:57.538403Z","shell.execute_reply":"2022-08-09T11:50:57.543172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.merge(data,temp,on='Cabin',how='left')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:58.347616Z","iopub.execute_input":"2022-08-09T11:50:58.348216Z","iopub.status.idle":"2022-08-09T11:50:58.356365Z","shell.execute_reply.started":"2022-08-09T11:50:58.348169Z","shell.execute_reply":"2022-08-09T11:50:58.355470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:59.152799Z","iopub.execute_input":"2022-08-09T11:50:59.153441Z","iopub.status.idle":"2022-08-09T11:50:59.170818Z","shell.execute_reply.started":"2022-08-09T11:50:59.153405Z","shell.execute_reply":"2022-08-09T11:50:59.169425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(['Name','Ticket','Cabin'],inplace=True,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:50:59.807163Z","iopub.execute_input":"2022-08-09T11:50:59.808135Z","iopub.status.idle":"2022-08-09T11:50:59.815254Z","shell.execute_reply.started":"2022-08-09T11:50:59.808095Z","shell.execute_reply":"2022-08-09T11:50:59.814124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:51:12.572647Z","iopub.execute_input":"2022-08-09T11:51:12.573077Z","iopub.status.idle":"2022-08-09T11:51:12.589872Z","shell.execute_reply.started":"2022-08-09T11:51:12.573038Z","shell.execute_reply":"2022-08-09T11:51:12.588911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.set_index('PassengerId',inplace=True,drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:53:03.387724Z","iopub.execute_input":"2022-08-09T11:53:03.388166Z","iopub.status.idle":"2022-08-09T11:53:03.394737Z","shell.execute_reply.started":"2022-08-09T11:53:03.388128Z","shell.execute_reply":"2022-08-09T11:53:03.393484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T11:53:09.622638Z","iopub.execute_input":"2022-08-09T11:53:09.623099Z","iopub.status.idle":"2022-08-09T11:53:09.638742Z","shell.execute_reply.started":"2022-08-09T11:53:09.623061Z","shell.execute_reply":"2022-08-09T11:53:09.637894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}