{"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-07-31T21:19:51.286864Z","iopub.execute_input":"2022-07-31T21:19:51.287929Z","iopub.status.idle":"2022-07-31T21:19:51.319688Z","shell.execute_reply.started":"2022-07-31T21:19:51.287791Z","shell.execute_reply":"2022-07-31T21:19:51.318335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:51.321953Z","iopub.execute_input":"2022-07-31T21:19:51.322643Z","iopub.status.idle":"2022-07-31T21:19:52.708566Z","shell.execute_reply.started":"2022-07-31T21:19:51.322603Z","shell.execute_reply":"2022-07-31T21:19:52.706892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('/kaggle/input/titanic/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.711372Z","iopub.execute_input":"2022-07-31T21:19:52.712782Z","iopub.status.idle":"2022-07-31T21:19:52.745326Z","shell.execute_reply.started":"2022-07-31T21:19:52.712721Z","shell.execute_reply":"2022-07-31T21:19:52.743546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.749045Z","iopub.execute_input":"2022-07-31T21:19:52.749511Z","iopub.status.idle":"2022-07-31T21:19:52.788380Z","shell.execute_reply.started":"2022-07-31T21:19:52.749472Z","shell.execute_reply":"2022-07-31T21:19:52.786772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.read_csv('/kaggle/input/titanic/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.791414Z","iopub.execute_input":"2022-07-31T21:19:52.792518Z","iopub.status.idle":"2022-07-31T21:19:52.810716Z","shell.execute_reply.started":"2022-07-31T21:19:52.792451Z","shell.execute_reply":"2022-07-31T21:19:52.809350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.812523Z","iopub.execute_input":"2022-07-31T21:19:52.813786Z","iopub.status.idle":"2022-07-31T21:19:52.836333Z","shell.execute_reply.started":"2022-07-31T21:19:52.813728Z","shell.execute_reply":"2022-07-31T21:19:52.835396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.837872Z","iopub.execute_input":"2022-07-31T21:19:52.838621Z","iopub.status.idle":"2022-07-31T21:19:52.868585Z","shell.execute_reply.started":"2022-07-31T21:19:52.838583Z","shell.execute_reply":"2022-07-31T21:19:52.867247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 7 numerical features and 5 categorical features","metadata":{}},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.870836Z","iopub.execute_input":"2022-07-31T21:19:52.871892Z","iopub.status.idle":"2022-07-31T21:19:52.887087Z","shell.execute_reply.started":"2022-07-31T21:19:52.871842Z","shell.execute_reply":"2022-07-31T21:19:52.885390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.888927Z","iopub.execute_input":"2022-07-31T21:19:52.889647Z","iopub.status.idle":"2022-07-31T21:19:52.944503Z","shell.execute_reply.started":"2022-07-31T21:19:52.889607Z","shell.execute_reply":"2022-07-31T21:19:52.942809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Exploring Passenger ID***","metadata":{}},{"cell_type":"code","source":"data['PassengerId'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.950249Z","iopub.execute_input":"2022-07-31T21:19:52.951110Z","iopub.status.idle":"2022-07-31T21:19:52.959209Z","shell.execute_reply.started":"2022-07-31T21:19:52.951038Z","shell.execute_reply":"2022-07-31T21:19:52.958313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"All the passenger id are unique","metadata":{}},{"cell_type":"code","source":"data[['PassengerId', 'Survived']]","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.961379Z","iopub.execute_input":"2022-07-31T21:19:52.962112Z","iopub.status.idle":"2022-07-31T21:19:52.982884Z","shell.execute_reply.started":"2022-07-31T21:19:52.962073Z","shell.execute_reply":"2022-07-31T21:19:52.981391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Exploring Pclass***","metadata":{}},{"cell_type":"code","source":"data['Pclass'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.984592Z","iopub.execute_input":"2022-07-31T21:19:52.985358Z","iopub.status.idle":"2022-07-31T21:19:52.993849Z","shell.execute_reply.started":"2022-07-31T21:19:52.985310Z","shell.execute_reply":"2022-07-31T21:19:52.992392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Pclass'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:52.995542Z","iopub.execute_input":"2022-07-31T21:19:52.996305Z","iopub.status.idle":"2022-07-31T21:19:53.009578Z","shell.execute_reply.started":"2022-07-31T21:19:52.996232Z","shell.execute_reply":"2022-07-31T21:19:53.007869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Pclass'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.012012Z","iopub.execute_input":"2022-07-31T21:19:53.012970Z","iopub.status.idle":"2022-07-31T21:19:53.023557Z","shell.execute_reply.started":"2022-07-31T21:19:53.012920Z","shell.execute_reply":"2022-07-31T21:19:53.022297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Survived', 'Pclass']].groupby(['Survived', 'Pclass']).size().reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.026119Z","iopub.execute_input":"2022-07-31T21:19:53.027085Z","iopub.status.idle":"2022-07-31T21:19:53.047043Z","shell.execute_reply.started":"2022-07-31T21:19:53.027021Z","shell.execute_reply":"2022-07-31T21:19:53.045423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Persons with Pclass 1 are most likely to survive whereas persons with Pclass 3 are not likely to survive","metadata":{}},{"cell_type":"code","source":"data.boxplot(column='Pclass')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.049143Z","iopub.execute_input":"2022-07-31T21:19:53.049967Z","iopub.status.idle":"2022-07-31T21:19:53.332323Z","shell.execute_reply.started":"2022-07-31T21:19:53.049922Z","shell.execute_reply":"2022-07-31T21:19:53.330313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are no outliers","metadata":{}},{"cell_type":"markdown","source":"***Exploring Names***","metadata":{}},{"cell_type":"code","source":"data['Name'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.334055Z","iopub.execute_input":"2022-07-31T21:19:53.335651Z","iopub.status.idle":"2022-07-31T21:19:53.344497Z","shell.execute_reply.started":"2022-07-31T21:19:53.335604Z","shell.execute_reply":"2022-07-31T21:19:53.343148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"All names are unique","metadata":{}},{"cell_type":"markdown","source":"***Exploring sex***","metadata":{}},{"cell_type":"code","source":"data['Sex'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.347007Z","iopub.execute_input":"2022-07-31T21:19:53.348106Z","iopub.status.idle":"2022-07-31T21:19:53.361873Z","shell.execute_reply.started":"2022-07-31T21:19:53.348054Z","shell.execute_reply":"2022-07-31T21:19:53.360372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the passengers were male","metadata":{}},{"cell_type":"code","source":"data['Sex'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.364158Z","iopub.execute_input":"2022-07-31T21:19:53.365389Z","iopub.status.idle":"2022-07-31T21:19:53.375962Z","shell.execute_reply.started":"2022-07-31T21:19:53.365331Z","shell.execute_reply":"2022-07-31T21:19:53.374543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Survived', 'Sex']].groupby(['Survived', 'Sex']).size().reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.378220Z","iopub.execute_input":"2022-07-31T21:19:53.379252Z","iopub.status.idle":"2022-07-31T21:19:53.399851Z","shell.execute_reply.started":"2022-07-31T21:19:53.379199Z","shell.execute_reply":"2022-07-31T21:19:53.398376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the male could not survive and females are most likely to be survived","metadata":{}},{"cell_type":"code","source":"data[['Pclass', 'Sex']].groupby(['Pclass', 'Sex']).size().reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.401763Z","iopub.execute_input":"2022-07-31T21:19:53.402708Z","iopub.status.idle":"2022-07-31T21:19:53.425342Z","shell.execute_reply.started":"2022-07-31T21:19:53.402651Z","shell.execute_reply":"2022-07-31T21:19:53.423477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In all the classes, there were more male than female with highest difference being in class 3","metadata":{}},{"cell_type":"markdown","source":"***Exploring Age***","metadata":{}},{"cell_type":"code","source":"data['Age'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.427521Z","iopub.execute_input":"2022-07-31T21:19:53.428377Z","iopub.status.idle":"2022-07-31T21:19:53.440174Z","shell.execute_reply.started":"2022-07-31T21:19:53.428320Z","shell.execute_reply":"2022-07-31T21:19:53.437745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 177 missing values","metadata":{}},{"cell_type":"code","source":"data['Age'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.443665Z","iopub.execute_input":"2022-07-31T21:19:53.444547Z","iopub.status.idle":"2022-07-31T21:19:53.459517Z","shell.execute_reply.started":"2022-07-31T21:19:53.444486Z","shell.execute_reply":"2022-07-31T21:19:53.458012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Age']].describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.461874Z","iopub.execute_input":"2022-07-31T21:19:53.462890Z","iopub.status.idle":"2022-07-31T21:19:53.490526Z","shell.execute_reply.started":"2022-07-31T21:19:53.462831Z","shell.execute_reply":"2022-07-31T21:19:53.488892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The persons ranged from younger to older with average being approx 29 years old","metadata":{}},{"cell_type":"code","source":"data[['Age', 'Survived']].groupby(['Age', 'Survived']).size().reset_index().sort_values(by= 0, ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.493514Z","iopub.execute_input":"2022-07-31T21:19:53.494651Z","iopub.status.idle":"2022-07-31T21:19:53.521840Z","shell.execute_reply.started":"2022-07-31T21:19:53.494593Z","shell.execute_reply":"2022-07-31T21:19:53.520467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.boxplot(column='Age')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.523640Z","iopub.execute_input":"2022-07-31T21:19:53.524716Z","iopub.status.idle":"2022-07-31T21:19:53.737348Z","shell.execute_reply.started":"2022-07-31T21:19:53.524618Z","shell.execute_reply":"2022-07-31T21:19:53.735655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are certain outliers","metadata":{}},{"cell_type":"code","source":"Q1 = data['Age'].quantile(0.25)\nQ3 = data['Age'].quantile(0.75)\nIQR = Q3 - Q1\n((data['Age'] < (Q1 - 1.5 * IQR)) | (data['Age'] > (Q3 + 1.5 * IQR))).sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.739607Z","iopub.execute_input":"2022-07-31T21:19:53.740761Z","iopub.status.idle":"2022-07-31T21:19:53.757968Z","shell.execute_reply.started":"2022-07-31T21:19:53.740686Z","shell.execute_reply":"2022-07-31T21:19:53.756879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 11 outliers","metadata":{}},{"cell_type":"markdown","source":"***Exploring siblings***","metadata":{}},{"cell_type":"code","source":"data['SibSp'].value_counts().sort_values()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.770258Z","iopub.execute_input":"2022-07-31T21:19:53.772153Z","iopub.status.idle":"2022-07-31T21:19:53.782708Z","shell.execute_reply.started":"2022-07-31T21:19:53.772100Z","shell.execute_reply":"2022-07-31T21:19:53.781359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Maximum people had 0 siblings and 5 persons had maximum of 5 sibling","metadata":{}},{"cell_type":"code","source":"data[['Name', 'SibSp']].groupby(by=['Name', 'SibSp']).size().reset_index().sort_values(by=['SibSp'], ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.784791Z","iopub.execute_input":"2022-07-31T21:19:53.786202Z","iopub.status.idle":"2022-07-31T21:19:53.812572Z","shell.execute_reply.started":"2022-07-31T21:19:53.786104Z","shell.execute_reply":"2022-07-31T21:19:53.811537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.boxplot(column='SibSp')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:53.813794Z","iopub.execute_input":"2022-07-31T21:19:53.815320Z","iopub.status.idle":"2022-07-31T21:19:54.034713Z","shell.execute_reply.started":"2022-07-31T21:19:53.815207Z","shell.execute_reply":"2022-07-31T21:19:54.033132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are certain outliers","metadata":{}},{"cell_type":"code","source":"Q1 = data['SibSp'].quantile(0.25)\nQ3 = data['SibSp'].quantile(0.75)\nIQR = Q3 - Q1\n((data['SibSp'] < (Q1 - 1.5 * IQR)) | (data['SibSp'] > (Q3 + 1.5 * IQR))).sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.037728Z","iopub.execute_input":"2022-07-31T21:19:54.038516Z","iopub.status.idle":"2022-07-31T21:19:54.055714Z","shell.execute_reply.started":"2022-07-31T21:19:54.038460Z","shell.execute_reply":"2022-07-31T21:19:54.053859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Toal outliers: 46","metadata":{}},{"cell_type":"markdown","source":"***Exploring ticket number***","metadata":{}},{"cell_type":"code","source":"data['Ticket'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.057737Z","iopub.execute_input":"2022-07-31T21:19:54.059143Z","iopub.status.idle":"2022-07-31T21:19:54.071176Z","shell.execute_reply.started":"2022-07-31T21:19:54.059079Z","shell.execute_reply":"2022-07-31T21:19:54.069469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are certain duplicates in ticket numbers","metadata":{}},{"cell_type":"code","source":"data['Ticket'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.074923Z","iopub.execute_input":"2022-07-31T21:19:54.076576Z","iopub.status.idle":"2022-07-31T21:19:54.086416Z","shell.execute_reply.started":"2022-07-31T21:19:54.076511Z","shell.execute_reply":"2022-07-31T21:19:54.085072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Name', 'Ticket']].groupby(by=['Name', 'Ticket']).size().reset_index().sort_values(by='Ticket', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.088006Z","iopub.execute_input":"2022-07-31T21:19:54.089350Z","iopub.status.idle":"2022-07-31T21:19:54.119424Z","shell.execute_reply.started":"2022-07-31T21:19:54.089110Z","shell.execute_reply":"2022-07-31T21:19:54.117775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[data['Ticket'] == '110152']","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.121184Z","iopub.execute_input":"2022-07-31T21:19:54.123139Z","iopub.status.idle":"2022-07-31T21:19:54.145554Z","shell.execute_reply.started":"2022-07-31T21:19:54.123075Z","shell.execute_reply":"2022-07-31T21:19:54.144424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Exploring parents***","metadata":{}},{"cell_type":"code","source":"data['Parch'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.147146Z","iopub.execute_input":"2022-07-31T21:19:54.147872Z","iopub.status.idle":"2022-07-31T21:19:54.160727Z","shell.execute_reply.started":"2022-07-31T21:19:54.147829Z","shell.execute_reply":"2022-07-31T21:19:54.159378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the children came alone followed by few coming with only one parent","metadata":{}},{"cell_type":"code","source":"data['Parch'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.162552Z","iopub.execute_input":"2022-07-31T21:19:54.163886Z","iopub.status.idle":"2022-07-31T21:19:54.176612Z","shell.execute_reply.started":"2022-07-31T21:19:54.163838Z","shell.execute_reply":"2022-07-31T21:19:54.174995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.boxplot(column='Parch')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.178361Z","iopub.execute_input":"2022-07-31T21:19:54.179422Z","iopub.status.idle":"2022-07-31T21:19:54.402775Z","shell.execute_reply.started":"2022-07-31T21:19:54.179381Z","shell.execute_reply":"2022-07-31T21:19:54.400866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are many outliers","metadata":{}},{"cell_type":"code","source":"Q1 = data['Parch'].quantile(0.25)\nQ3 = data['Parch'].quantile(0.75)\nIQR = Q3 - Q1\n((data['Parch'] < (Q1 - 1.5 * IQR)) | (data['Parch'] > (Q3 + 1.5 * IQR))).sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.404671Z","iopub.execute_input":"2022-07-31T21:19:54.405209Z","iopub.status.idle":"2022-07-31T21:19:54.425976Z","shell.execute_reply.started":"2022-07-31T21:19:54.405158Z","shell.execute_reply":"2022-07-31T21:19:54.422221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Total outliers: 213","metadata":{}},{"cell_type":"code","source":"data[['Name', 'Parch', 'SibSp']].groupby(by=['Name', 'Parch', 'SibSp']).size().reset_index().sort_values(by=['Parch'], ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.428908Z","iopub.execute_input":"2022-07-31T21:19:54.429996Z","iopub.status.idle":"2022-07-31T21:19:54.463663Z","shell.execute_reply.started":"2022-07-31T21:19:54.429943Z","shell.execute_reply":"2022-07-31T21:19:54.462361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Exploring fare***","metadata":{}},{"cell_type":"code","source":"data['Fare'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.465683Z","iopub.execute_input":"2022-07-31T21:19:54.467040Z","iopub.status.idle":"2022-07-31T21:19:54.478632Z","shell.execute_reply.started":"2022-07-31T21:19:54.466982Z","shell.execute_reply":"2022-07-31T21:19:54.476349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Fare']].describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.480038Z","iopub.execute_input":"2022-07-31T21:19:54.480460Z","iopub.status.idle":"2022-07-31T21:19:54.504235Z","shell.execute_reply.started":"2022-07-31T21:19:54.480424Z","shell.execute_reply":"2022-07-31T21:19:54.502967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Fare'].value_counts().sort_values(ascending=False).head(20)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.507653Z","iopub.execute_input":"2022-07-31T21:19:54.508959Z","iopub.status.idle":"2022-07-31T21:19:54.524563Z","shell.execute_reply.started":"2022-07-31T21:19:54.508908Z","shell.execute_reply":"2022-07-31T21:19:54.523015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the fare prices were 8.05 ","metadata":{}},{"cell_type":"code","source":"data[['Age', 'Fare']].groupby(by=['Age', 'Fare']).size().reset_index().sort_values(by='Fare', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.527146Z","iopub.execute_input":"2022-07-31T21:19:54.528607Z","iopub.status.idle":"2022-07-31T21:19:54.555905Z","shell.execute_reply.started":"2022-07-31T21:19:54.528534Z","shell.execute_reply":"2022-07-31T21:19:54.554150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Pclass', 'Fare']].groupby(by=['Pclass', 'Fare']).size().reset_index().sort_values(by='Fare', ascending=False).head(40)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.557916Z","iopub.execute_input":"2022-07-31T21:19:54.558694Z","iopub.status.idle":"2022-07-31T21:19:54.592648Z","shell.execute_reply.started":"2022-07-31T21:19:54.558647Z","shell.execute_reply":"2022-07-31T21:19:54.591076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Pclass 1 has highest fare. Max price for pclass 2 is 73.5","metadata":{}},{"cell_type":"code","source":"data[['Sex', 'Pclass', 'Fare']].groupby(by=['Sex', 'Pclass', 'Fare']).size().reset_index().sort_values(by='Fare', ascending=False).head(40)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.594572Z","iopub.execute_input":"2022-07-31T21:19:54.595200Z","iopub.status.idle":"2022-07-31T21:19:54.629187Z","shell.execute_reply.started":"2022-07-31T21:19:54.595160Z","shell.execute_reply":"2022-07-31T21:19:54.627254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.boxplot(column='Fare')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.634083Z","iopub.execute_input":"2022-07-31T21:19:54.634579Z","iopub.status.idle":"2022-07-31T21:19:54.842844Z","shell.execute_reply.started":"2022-07-31T21:19:54.634542Z","shell.execute_reply":"2022-07-31T21:19:54.840771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Q1 = data['Fare'].quantile(0.25)\nQ3 = data['Fare'].quantile(0.75)\nIQR = Q3 - Q1\n((data['Fare'] < (Q1 - 1.5 * IQR)) | (data['Fare'] > (Q3 + 1.5 * IQR))).sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.844935Z","iopub.execute_input":"2022-07-31T21:19:54.845427Z","iopub.status.idle":"2022-07-31T21:19:54.860713Z","shell.execute_reply.started":"2022-07-31T21:19:54.845389Z","shell.execute_reply":"2022-07-31T21:19:54.859069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 116 outliers","metadata":{}},{"cell_type":"markdown","source":"***Exploring Cabin***","metadata":{}},{"cell_type":"code","source":"data['Cabin'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.863037Z","iopub.execute_input":"2022-07-31T21:19:54.863786Z","iopub.status.idle":"2022-07-31T21:19:54.872194Z","shell.execute_reply.started":"2022-07-31T21:19:54.863743Z","shell.execute_reply":"2022-07-31T21:19:54.870961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Cabin'].value_counts().sort_values(ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.873826Z","iopub.execute_input":"2022-07-31T21:19:54.874738Z","iopub.status.idle":"2022-07-31T21:19:54.889047Z","shell.execute_reply.started":"2022-07-31T21:19:54.874695Z","shell.execute_reply":"2022-07-31T21:19:54.887642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Cabin'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.890515Z","iopub.execute_input":"2022-07-31T21:19:54.891084Z","iopub.status.idle":"2022-07-31T21:19:54.900046Z","shell.execute_reply.started":"2022-07-31T21:19:54.891050Z","shell.execute_reply":"2022-07-31T21:19:54.898140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of cabin numbers are missing","metadata":{}},{"cell_type":"code","source":"data[['Cabin', 'Fare']].groupby(by=['Cabin', 'Fare']).size().reset_index().sort_values(by='Fare', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.901919Z","iopub.execute_input":"2022-07-31T21:19:54.902974Z","iopub.status.idle":"2022-07-31T21:19:54.932587Z","shell.execute_reply.started":"2022-07-31T21:19:54.902927Z","shell.execute_reply":"2022-07-31T21:19:54.931225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Cabin', 'Sex']].groupby(by=['Cabin', 'Sex']).size().reset_index().sort_values(by='Sex', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.935336Z","iopub.execute_input":"2022-07-31T21:19:54.936327Z","iopub.status.idle":"2022-07-31T21:19:54.970523Z","shell.execute_reply.started":"2022-07-31T21:19:54.936254Z","shell.execute_reply":"2022-07-31T21:19:54.968721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['Cabin', 'Age']].groupby(by=['Cabin', 'Age']).size().reset_index().sort_values(by='Age', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:54.972805Z","iopub.execute_input":"2022-07-31T21:19:54.974991Z","iopub.status.idle":"2022-07-31T21:19:55.054020Z","shell.execute_reply.started":"2022-07-31T21:19:54.974906Z","shell.execute_reply":"2022-07-31T21:19:55.051102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Exploring embarked***","metadata":{}},{"cell_type":"code","source":"data['Embarked'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.056935Z","iopub.execute_input":"2022-07-31T21:19:55.060162Z","iopub.status.idle":"2022-07-31T21:19:55.074354Z","shell.execute_reply.started":"2022-07-31T21:19:55.060079Z","shell.execute_reply":"2022-07-31T21:19:55.072761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Embarked'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.075897Z","iopub.execute_input":"2022-07-31T21:19:55.076612Z","iopub.status.idle":"2022-07-31T21:19:55.088151Z","shell.execute_reply.started":"2022-07-31T21:19:55.076560Z","shell.execute_reply":"2022-07-31T21:19:55.087246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Port of embarkation was max for Southhampton","metadata":{}},{"cell_type":"code","source":"data['Embarked'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.089802Z","iopub.execute_input":"2022-07-31T21:19:55.090553Z","iopub.status.idle":"2022-07-31T21:19:55.102926Z","shell.execute_reply.started":"2022-07-31T21:19:55.090475Z","shell.execute_reply":"2022-07-31T21:19:55.101716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 2 missing values","metadata":{}},{"cell_type":"markdown","source":"***Label Encoding categorical columns (After this to be perfromed in test data also)***","metadata":{}},{"cell_type":"code","source":"print(data.isna().sum())","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.104609Z","iopub.execute_input":"2022-07-31T21:19:55.105410Z","iopub.status.idle":"2022-07-31T21:19:55.118787Z","shell.execute_reply.started":"2022-07-31T21:19:55.105368Z","shell.execute_reply":"2022-07-31T21:19:55.117678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since cabin has most of the missing values, we will drop the column","metadata":{}},{"cell_type":"code","source":"data.drop(columns=['Cabin'], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.120714Z","iopub.execute_input":"2022-07-31T21:19:55.121125Z","iopub.status.idle":"2022-07-31T21:19:55.129406Z","shell.execute_reply.started":"2022-07-31T21:19:55.121083Z","shell.execute_reply":"2022-07-31T21:19:55.127052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.131115Z","iopub.execute_input":"2022-07-31T21:19:55.132053Z","iopub.status.idle":"2022-07-31T21:19:55.154823Z","shell.execute_reply.started":"2022-07-31T21:19:55.132005Z","shell.execute_reply":"2022-07-31T21:19:55.153371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Categorical columns are Name, Sex, Ticket, Cabin, Embarked","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.156472Z","iopub.execute_input":"2022-07-31T21:19:55.157522Z","iopub.status.idle":"2022-07-31T21:19:55.349689Z","shell.execute_reply.started":"2022-07-31T21:19:55.157480Z","shell.execute_reply":"2022-07-31T21:19:55.348188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.351572Z","iopub.execute_input":"2022-07-31T21:19:55.352099Z","iopub.status.idle":"2022-07-31T21:19:55.359738Z","shell.execute_reply.started":"2022-07-31T21:19:55.352048Z","shell.execute_reply":"2022-07-31T21:19:55.358287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Sex'] = le.fit_transform(data['Sex'])\ndata['Embarked'] = le.fit_transform(data['Embarked'])\ndata['Ticket'] = le.fit_transform(data['Ticket'])\ndata['Name'] = le.fit_transform(data['Name'])","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.361535Z","iopub.execute_input":"2022-07-31T21:19:55.362177Z","iopub.status.idle":"2022-07-31T21:19:55.388973Z","shell.execute_reply.started":"2022-07-31T21:19:55.362121Z","shell.execute_reply":"2022-07-31T21:19:55.387379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Dropping unuseful columns***","metadata":{}},{"cell_type":"code","source":"for x in data.columns:\n    Q1 = data[x].quantile(0.25)\n    Q3 = data[x].quantile(0.75)\n    IQR = Q3 - Q1\n    print(x,\":\", ((data[x] < (Q1 - 1.5 * IQR)) | (data[x] > (Q3 + 1.5 * IQR))).sum())","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.391151Z","iopub.execute_input":"2022-07-31T21:19:55.392040Z","iopub.status.idle":"2022-07-31T21:19:55.463463Z","shell.execute_reply.started":"2022-07-31T21:19:55.391985Z","shell.execute_reply":"2022-07-31T21:19:55.461596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(data.isna().sum())","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.465571Z","iopub.execute_input":"2022-07-31T21:19:55.466460Z","iopub.status.idle":"2022-07-31T21:19:55.484091Z","shell.execute_reply.started":"2022-07-31T21:19:55.466404Z","shell.execute_reply":"2022-07-31T21:19:55.482329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_to_reorder = data.pop('Survived')\ndata.insert(len(data. columns), 'Survived', column_to_reorder)\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.486711Z","iopub.execute_input":"2022-07-31T21:19:55.487328Z","iopub.status.idle":"2022-07-31T21:19:55.514180Z","shell.execute_reply.started":"2022-07-31T21:19:55.487235Z","shell.execute_reply":"2022-07-31T21:19:55.512899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cormat = data.corr()\ncormat","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.516089Z","iopub.execute_input":"2022-07-31T21:19:55.517067Z","iopub.status.idle":"2022-07-31T21:19:55.551218Z","shell.execute_reply.started":"2022-07-31T21:19:55.517017Z","shell.execute_reply":"2022-07-31T21:19:55.549979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30,10))\nsns.heatmap(cormat, annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:55.553314Z","iopub.execute_input":"2022-07-31T21:19:55.554097Z","iopub.status.idle":"2022-07-31T21:19:56.518696Z","shell.execute_reply.started":"2022-07-31T21:19:55.554040Z","shell.execute_reply":"2022-07-31T21:19:56.517450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"drop_columns = ['PassengerId', 'Name', 'SibSp', 'Parch', 'Age']","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:56.519854Z","iopub.execute_input":"2022-07-31T21:19:56.520227Z","iopub.status.idle":"2022-07-31T21:19:56.526435Z","shell.execute_reply.started":"2022-07-31T21:19:56.520194Z","shell.execute_reply":"2022-07-31T21:19:56.524766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_copy = data.drop(columns=drop_columns, axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:56.527705Z","iopub.execute_input":"2022-07-31T21:19:56.528099Z","iopub.status.idle":"2022-07-31T21:19:56.544713Z","shell.execute_reply.started":"2022-07-31T21:19:56.528065Z","shell.execute_reply":"2022-07-31T21:19:56.543467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_copy.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:56.547050Z","iopub.execute_input":"2022-07-31T21:19:56.547865Z","iopub.status.idle":"2022-07-31T21:19:56.567156Z","shell.execute_reply.started":"2022-07-31T21:19:56.547813Z","shell.execute_reply":"2022-07-31T21:19:56.566045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in data_copy.columns:\n    Q1 = data_copy[x].quantile(0.25)\n    Q3 = data_copy[x].quantile(0.75)\n    IQR = Q3 - Q1\n    print(x,\":\", ((data_copy[x] < (Q1 - 1.5 * IQR)) | (data_copy[x] > (Q3 + 1.5 * IQR))).sum())","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:56.568956Z","iopub.execute_input":"2022-07-31T21:19:56.569662Z","iopub.status.idle":"2022-07-31T21:19:56.599056Z","shell.execute_reply.started":"2022-07-31T21:19:56.569618Z","shell.execute_reply":"2022-07-31T21:19:56.597740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Handling outliers in fare***","metadata":{}},{"cell_type":"code","source":"mean = data_copy['Fare'].mean()\nQ1 = data_copy['Fare'].quantile(0.25)\nQ3 = data_copy['Fare'].quantile(0.75)\nIQR = Q3 - Q1\nfor x in range(len(data_copy['Fare'])):\n    if ((data_copy['Fare'][x] < (Q1 - 1.5 * IQR)) | (data_copy['Fare'][x] > (Q3 + 1.5 * IQR))):\n        data_copy['Fare'][x] = mean","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:56.600931Z","iopub.execute_input":"2022-07-31T21:19:56.601728Z","iopub.status.idle":"2022-07-31T21:19:56.670453Z","shell.execute_reply.started":"2022-07-31T21:19:56.601690Z","shell.execute_reply":"2022-07-31T21:19:56.668818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***","metadata":{}},{"cell_type":"code","source":"sns.pairplot(data_copy)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:19:56.672425Z","iopub.execute_input":"2022-07-31T21:19:56.673141Z","iopub.status.idle":"2022-07-31T21:20:04.840116Z","shell.execute_reply.started":"2022-07-31T21:19:56.673101Z","shell.execute_reply":"2022-07-31T21:20:04.838161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = data_copy.iloc[ : ,:5].values\nX.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.842457Z","iopub.execute_input":"2022-07-31T21:20:04.842918Z","iopub.status.idle":"2022-07-31T21:20:04.853915Z","shell.execute_reply.started":"2022-07-31T21:20:04.842882Z","shell.execute_reply":"2022-07-31T21:20:04.852186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = data_copy.iloc[ : ,-1].values","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.855725Z","iopub.execute_input":"2022-07-31T21:20:04.856144Z","iopub.status.idle":"2022-07-31T21:20:04.863226Z","shell.execute_reply.started":"2022-07-31T21:20:04.856113Z","shell.execute_reply":"2022-07-31T21:20:04.861606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nsc = StandardScaler()\nX = sc.fit_transform(X)\nprint(X)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.865496Z","iopub.execute_input":"2022-07-31T21:20:04.867129Z","iopub.status.idle":"2022-07-31T21:20:04.882958Z","shell.execute_reply.started":"2022-07-31T21:20:04.867020Z","shell.execute_reply":"2022-07-31T21:20:04.881675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Performing the same on the test data***","metadata":{}},{"cell_type":"code","source":"test_data.drop(columns=['Cabin'], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.885258Z","iopub.execute_input":"2022-07-31T21:20:04.886014Z","iopub.status.idle":"2022-07-31T21:20:04.895234Z","shell.execute_reply.started":"2022-07-31T21:20:04.885971Z","shell.execute_reply":"2022-07-31T21:20:04.893301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"drop_columns = ['PassengerId', 'Name', 'SibSp', 'Parch', 'Age']\ntest_data = test_data.drop(columns=drop_columns, axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.898819Z","iopub.execute_input":"2022-07-31T21:20:04.899644Z","iopub.status.idle":"2022-07-31T21:20:04.908179Z","shell.execute_reply.started":"2022-07-31T21:20:04.899602Z","shell.execute_reply":"2022-07-31T21:20:04.906163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.910706Z","iopub.execute_input":"2022-07-31T21:20:04.911543Z","iopub.status.idle":"2022-07-31T21:20:04.923519Z","shell.execute_reply.started":"2022-07-31T21:20:04.911494Z","shell.execute_reply":"2022-07-31T21:20:04.921966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data['Sex'] = le.fit_transform(test_data['Sex'])\ntest_data['Embarked'] = le.fit_transform(test_data['Embarked'])\ntest_data['Ticket'] = le.fit_transform(test_data['Ticket'])","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.926176Z","iopub.execute_input":"2022-07-31T21:20:04.926743Z","iopub.status.idle":"2022-07-31T21:20:04.943102Z","shell.execute_reply.started":"2022-07-31T21:20:04.926703Z","shell.execute_reply":"2022-07-31T21:20:04.941069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in test_data.columns:\n    Q1 = test_data[x].quantile(0.25)\n    Q3 = test_data[x].quantile(0.75)\n    IQR = Q3 - Q1\n    print(x,\":\", ((test_data[x] < (Q1 - 1.5 * IQR)) | (test_data[x] > (Q3 + 1.5 * IQR))).sum())","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.958024Z","iopub.execute_input":"2022-07-31T21:20:04.959385Z","iopub.status.idle":"2022-07-31T21:20:04.987693Z","shell.execute_reply.started":"2022-07-31T21:20:04.959311Z","shell.execute_reply":"2022-07-31T21:20:04.985382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = test_data['Fare'].mean()\nQ1 = test_data['Fare'].quantile(0.25)\nQ3 = test_data['Fare'].quantile(0.75)\nIQR = Q3 - Q1\nfor x in range(len(test_data['Fare'])):\n    if ((test_data['Fare'][x] < (Q1 - 1.5 * IQR)) | (test_data['Fare'][x] > (Q3 + 1.5 * IQR))):\n        test_data['Fare'][x] = mean\n    if pd.isnull(test_data['Fare'][x]):\n        test_data['Fare'][x] = mean","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:04.989765Z","iopub.execute_input":"2022-07-31T21:20:04.990333Z","iopub.status.idle":"2022-07-31T21:20:05.042873Z","shell.execute_reply.started":"2022-07-31T21:20:04.990290Z","shell.execute_reply":"2022-07-31T21:20:05.041899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.044100Z","iopub.execute_input":"2022-07-31T21:20:05.044524Z","iopub.status.idle":"2022-07-31T21:20:05.054233Z","shell.execute_reply.started":"2022-07-31T21:20:05.044489Z","shell.execute_reply":"2022-07-31T21:20:05.052785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_data.isna().sum())","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.056737Z","iopub.execute_input":"2022-07-31T21:20:05.057610Z","iopub.status.idle":"2022-07-31T21:20:05.071452Z","shell.execute_reply.started":"2022-07-31T21:20:05.057564Z","shell.execute_reply":"2022-07-31T21:20:05.069357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.fit_transform(test_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.073489Z","iopub.execute_input":"2022-07-31T21:20:05.074557Z","iopub.status.idle":"2022-07-31T21:20:05.092729Z","shell.execute_reply.started":"2022-07-31T21:20:05.074498Z","shell.execute_reply":"2022-07-31T21:20:05.090723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Splitting the data***","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train, x_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 25)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.094623Z","iopub.execute_input":"2022-07-31T21:20:05.095682Z","iopub.status.idle":"2022-07-31T21:20:05.173856Z","shell.execute_reply.started":"2022-07-31T21:20:05.095615Z","shell.execute_reply":"2022-07-31T21:20:05.171876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Creating model***","metadata":{}},{"cell_type":"markdown","source":"**Testing Logistic Regression***","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score\nlr = LogisticRegression()\nlr.fit(x_train, y_train)\ny_pred = lr.predict(x_test)\nprint(\"Score:\", accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.177757Z","iopub.execute_input":"2022-07-31T21:20:05.178361Z","iopub.status.idle":"2022-07-31T21:20:05.281113Z","shell.execute_reply.started":"2022-07-31T21:20:05.178308Z","shell.execute_reply":"2022-07-31T21:20:05.279092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Testing Decision Tree**","metadata":{}},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier\ndt = DecisionTreeClassifier()\ndt.fit(x_train, y_train)\ny_pred = dt.predict(x_test)\nprint(\"Score:\", accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.283563Z","iopub.execute_input":"2022-07-31T21:20:05.284528Z","iopub.status.idle":"2022-07-31T21:20:05.393326Z","shell.execute_reply.started":"2022-07-31T21:20:05.284485Z","shell.execute_reply":"2022-07-31T21:20:05.390255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Testing SVC**","metadata":{}},{"cell_type":"code","source":"from sklearn.svm import SVC\nsvc = SVC()\nsvc.fit(x_train, y_train)\ny_pred = svc.predict(x_test)\nprint(\"Score:\", accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.395355Z","iopub.execute_input":"2022-07-31T21:20:05.395773Z","iopub.status.idle":"2022-07-31T21:20:05.427826Z","shell.execute_reply.started":"2022-07-31T21:20:05.395740Z","shell.execute_reply":"2022-07-31T21:20:05.426461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Testing random forest classifier**","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nrfc = RandomForestClassifier()\nrfc.fit(x_train, y_train)\ny_pred = rfc.predict(x_test)\nprint(\"Score:\", accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.430225Z","iopub.execute_input":"2022-07-31T21:20:05.431134Z","iopub.status.idle":"2022-07-31T21:20:05.800002Z","shell.execute_reply.started":"2022-07-31T21:20:05.431078Z","shell.execute_reply":"2022-07-31T21:20:05.798728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Testing KNN**","metadata":{}},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nneigh = KNeighborsClassifier(n_neighbors=6)\nneigh.fit(x_train, y_train)\ny_pred = neigh.predict(x_test)\nprint(\"Score:\", accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.801561Z","iopub.execute_input":"2022-07-31T21:20:05.801949Z","iopub.status.idle":"2022-07-31T21:20:05.823202Z","shell.execute_reply.started":"2022-07-31T21:20:05.801916Z","shell.execute_reply":"2022-07-31T21:20:05.821994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since SVC model has the highest accuracy, so, we will be using it","metadata":{}},{"cell_type":"code","source":"final=svc.predict(test_data)\nfinal","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.825497Z","iopub.execute_input":"2022-07-31T21:20:05.825908Z","iopub.status.idle":"2022-07-31T21:20:05.851990Z","shell.execute_reply.started":"2022-07-31T21:20:05.825875Z","shell.execute_reply":"2022-07-31T21:20:05.850604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv(r\"../input/titanic/test.csv\")\nsubmission = pd.DataFrame({\n    \"PassengerId\" : test[\"PassengerId\"],\n    \"Survived\" : final\n})\nsubmission.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.853526Z","iopub.execute_input":"2022-07-31T21:20:05.853984Z","iopub.status.idle":"2022-07-31T21:20:05.878149Z","shell.execute_reply.started":"2022-07-31T21:20:05.853949Z","shell.execute_reply":"2022-07-31T21:20:05.876045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T21:20:05.879836Z","iopub.execute_input":"2022-07-31T21:20:05.882898Z","iopub.status.idle":"2022-07-31T21:20:05.895913Z","shell.execute_reply.started":"2022-07-31T21:20:05.882842Z","shell.execute_reply":"2022-07-31T21:20:05.894357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}