{"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":"# Titanic ","metadata":{}},{"cell_type":"markdown","source":"### TABLE of CONTENTS:\n​\n* [Import Libraries](#sec1)\n* [Import CSV](#sec2)\n* [Basic Information](#sec3)\n* [EDA](#sec4)\n * [TABLEAU VISUALISATION](#sec4.1)\n* [Missing Values](#sec5)\n* [EDA2](#sec6)\n* [One Hot Encodind](#sec7)\n* [Train-Test Split](#sec8)\n* [Prediction](#sec9)","metadata":{}},{"cell_type":"markdown","source":"# Import Libraries <a class=\"anchor\" id=\"sec1\"></a>","metadata":{}},{"cell_type":"code","source":"#importing libraries\nimport warnings\nwarnings.filterwarnings('ignore')\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.740346Z","iopub.execute_input":"2022-08-13T17:59:42.740793Z","iopub.status.idle":"2022-08-13T17:59:42.746070Z","shell.execute_reply.started":"2022-08-13T17:59:42.740760Z","shell.execute_reply":"2022-08-13T17:59:42.744913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)\npd.set_option('display.max_rows', None)\npd.set_option('display.expand_frame_repr', False)\npd.set_option('max_colwidth', -1)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.747727Z","iopub.execute_input":"2022-08-13T17:59:42.748285Z","iopub.status.idle":"2022-08-13T17:59:42.761915Z","shell.execute_reply.started":"2022-08-13T17:59:42.748251Z","shell.execute_reply":"2022-08-13T17:59:42.760815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Import CSV <a class=\"anchor\" id=\"sec2\"></a>","metadata":{}},{"cell_type":"code","source":"df=pd.read_csv(\"../input/titanic/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.765216Z","iopub.execute_input":"2022-08-13T17:59:42.765757Z","iopub.status.idle":"2022-08-13T17:59:42.782274Z","shell.execute_reply.started":"2022-08-13T17:59:42.765720Z","shell.execute_reply":"2022-08-13T17:59:42.781023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.784471Z","iopub.execute_input":"2022-08-13T17:59:42.785017Z","iopub.status.idle":"2022-08-13T17:59:42.803512Z","shell.execute_reply.started":"2022-08-13T17:59:42.784984Z","shell.execute_reply":"2022-08-13T17:59:42.801648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test\ndf_t=pd.read_csv(\"../input/titanic/test.csv\")\ndf_t.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.804793Z","iopub.execute_input":"2022-08-13T17:59:42.805678Z","iopub.status.idle":"2022-08-13T17:59:42.826748Z","shell.execute_reply.started":"2022-08-13T17:59:42.805642Z","shell.execute_reply":"2022-08-13T17:59:42.825824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Basic Information <a class=\"anchor\" id=\"sec3\"></a>","metadata":{}},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.828664Z","iopub.execute_input":"2022-08-13T17:59:42.829344Z","iopub.status.idle":"2022-08-13T17:59:42.835669Z","shell.execute_reply.started":"2022-08-13T17:59:42.829310Z","shell.execute_reply":"2022-08-13T17:59:42.834656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.836853Z","iopub.execute_input":"2022-08-13T17:59:42.837705Z","iopub.status.idle":"2022-08-13T17:59:42.870794Z","shell.execute_reply.started":"2022-08-13T17:59:42.837669Z","shell.execute_reply":"2022-08-13T17:59:42.869898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.873017Z","iopub.execute_input":"2022-08-13T17:59:42.873743Z","iopub.status.idle":"2022-08-13T17:59:42.887658Z","shell.execute_reply.started":"2022-08-13T17:59:42.873708Z","shell.execute_reply":"2022-08-13T17:59:42.886650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.889884Z","iopub.execute_input":"2022-08-13T17:59:42.890763Z","iopub.status.idle":"2022-08-13T17:59:42.900129Z","shell.execute_reply.started":"2022-08-13T17:59:42.890729Z","shell.execute_reply":"2022-08-13T17:59:42.899058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.select_dtypes(include=['int64']).columns","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.902698Z","iopub.execute_input":"2022-08-13T17:59:42.903350Z","iopub.status.idle":"2022-08-13T17:59:42.913220Z","shell.execute_reply.started":"2022-08-13T17:59:42.903310Z","shell.execute_reply":"2022-08-13T17:59:42.912105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.select_dtypes(include=['float64']).columns","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.915548Z","iopub.execute_input":"2022-08-13T17:59:42.916311Z","iopub.status.idle":"2022-08-13T17:59:42.924590Z","shell.execute_reply.started":"2022-08-13T17:59:42.916277Z","shell.execute_reply":"2022-08-13T17:59:42.923645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.select_dtypes(include=['object']).columns","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.929881Z","iopub.execute_input":"2022-08-13T17:59:42.930346Z","iopub.status.idle":"2022-08-13T17:59:42.940574Z","shell.execute_reply.started":"2022-08-13T17:59:42.930321Z","shell.execute_reply":"2022-08-13T17:59:42.939616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA <a class=\"anchor\" id=\"sec4\"></a>\n","metadata":{}},{"cell_type":"code","source":"df['Sex'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:42.952627Z","iopub.execute_input":"2022-08-13T17:59:42.953149Z","iopub.status.idle":"2022-08-13T17:59:42.963331Z","shell.execute_reply.started":"2022-08-13T17:59:42.953123Z","shell.execute_reply":"2022-08-13T17:59:42.962187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Hence our data is not balanced with respect to age","metadata":{}},{"cell_type":"markdown","source":" # TABLEAU VISUALISATION <a class=\"anchor\" id=\"sec4.1\"></a>","metadata":{}},{"cell_type":"code","source":"%%HTML\n\n<div class='tableauPlaceholder' id='viz1658249328433' style='position: relative'><noscript><a href='#'><img alt='Embarked ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Em&#47;Embarked_16582487167490&#47;Embarked&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz'  style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='' /><param name='name' value='Embarked_16582487167490&#47;Embarked' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Em&#47;Embarked_16582487167490&#47;Embarked&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /><param name='language' value='en-US' /></object></div>                <script type='text/javascript'>                    var divElement = document.getElementById('viz1658249328433');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='100%';vizElement.style.height=(divElement.offsetWidth*0.75)+'px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                </script>","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T17:59:42.995753Z","iopub.execute_input":"2022-08-13T17:59:42.996014Z","iopub.status.idle":"2022-08-13T17:59:43.003736Z","shell.execute_reply.started":"2022-08-13T17:59:42.995991Z","shell.execute_reply":"2022-08-13T17:59:43.002654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Distribution of Port of Embarkation i.e. C = Cherbourg, Q = Queenstown, S = Southampton","metadata":{}},{"cell_type":"code","source":"%%HTML\n\n<div class='tableauPlaceholder' id='viz1658249378486' style='position: relative'><noscript><a href='#'><img alt='Sex ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Se&#47;Sex_16582487517970&#47;Sex&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz'  style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='' /><param name='name' value='Sex_16582487517970&#47;Sex' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Se&#47;Sex_16582487517970&#47;Sex&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /><param name='language' value='en-US' /></object></div>                <script type='text/javascript'>                    var divElement = document.getElementById('viz1658249378486');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='100%';vizElement.style.height=(divElement.offsetWidth*0.75)+'px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                </script>","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T17:59:43.037473Z","iopub.execute_input":"2022-08-13T17:59:43.038140Z","iopub.status.idle":"2022-08-13T17:59:43.046142Z","shell.execute_reply.started":"2022-08-13T17:59:43.038113Z","shell.execute_reply":"2022-08-13T17:59:43.045186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"ALERT: Can we conclude that Surival Chance of Male Passengers is more than female???\n       The answer is no....It is because the data is imbalanced w.r.t sex and the total no. of female passenger in the ship is low as compared to male.","metadata":{}},{"cell_type":"code","source":"%%HTML\n\n<div class='tableauPlaceholder' id='viz1658249440826' style='position: relative'><noscript><a href='#'><img alt='Age ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Ag&#47;Age_16582487844110&#47;Age&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz'  style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='' /><param name='name' value='Age_16582487844110&#47;Age' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Ag&#47;Age_16582487844110&#47;Age&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /><param name='language' value='en-US' /></object></div>                <script type='text/javascript'>                    var divElement = document.getElementById('viz1658249440826');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='100%';vizElement.style.height=(divElement.offsetWidth*0.75)+'px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                </script>","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T17:59:43.073876Z","iopub.execute_input":"2022-08-13T17:59:43.074538Z","iopub.status.idle":"2022-08-13T17:59:43.082224Z","shell.execute_reply.started":"2022-08-13T17:59:43.074508Z","shell.execute_reply":"2022-08-13T17:59:43.080970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Passengers survived in each age group.","metadata":{}},{"cell_type":"code","source":"%%HTML\n\n<div class='tableauPlaceholder' id='viz1658249508922' style='position: relative'><noscript><a href='#'><img alt='Age_Sex ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Ag&#47;Age_Sex&#47;Age_Sex&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz'  style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='' /><param name='name' value='Age_Sex&#47;Age_Sex' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Ag&#47;Age_Sex&#47;Age_Sex&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /><param name='language' value='en-US' /></object></div>                <script type='text/javascript'>                    var divElement = document.getElementById('viz1658249508922');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='100%';vizElement.style.height=(divElement.offsetWidth*0.75)+'px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                </script>","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T17:59:43.106123Z","iopub.execute_input":"2022-08-13T17:59:43.106896Z","iopub.status.idle":"2022-08-13T17:59:43.118434Z","shell.execute_reply.started":"2022-08-13T17:59:43.106865Z","shell.execute_reply":"2022-08-13T17:59:43.117344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%HTML\n\n<div class='tableauPlaceholder' id='viz1658249580704' style='position: relative'><noscript><a href='#'><img alt='Pclass ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Pc&#47;Pclass_16582489318780&#47;Pclass&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz'  style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='' /><param name='name' value='Pclass_16582489318780&#47;Pclass' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Pc&#47;Pclass_16582489318780&#47;Pclass&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /><param name='language' value='en-US' /></object></div>                <script type='text/javascript'>                    var divElement = document.getElementById('viz1658249580704');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='100%';vizElement.style.height=(divElement.offsetWidth*0.75)+'px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                </script>","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T17:59:43.136699Z","iopub.execute_input":"2022-08-13T17:59:43.137202Z","iopub.status.idle":"2022-08-13T17:59:43.144794Z","shell.execute_reply.started":"2022-08-13T17:59:43.137174Z","shell.execute_reply":"2022-08-13T17:59:43.143586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Distribution of ticket class. i.e. 1 = 1st, 2 = 2nd, 3 = 3rd","metadata":{}},{"cell_type":"markdown","source":"# Missing Values <a class=\"anchor\" id=\"sec5\"></a>","metadata":{}},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.154076Z","iopub.execute_input":"2022-08-13T17:59:43.154551Z","iopub.status.idle":"2022-08-13T17:59:43.165279Z","shell.execute_reply.started":"2022-08-13T17:59:43.154521Z","shell.execute_reply":"2022-08-13T17:59:43.163715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"100*(df.isnull().sum())/len(df)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.175196Z","iopub.execute_input":"2022-08-13T17:59:43.175810Z","iopub.status.idle":"2022-08-13T17:59:43.186566Z","shell.execute_reply.started":"2022-08-13T17:59:43.175775Z","shell.execute_reply":"2022-08-13T17:59:43.185439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We will drop cabin as it has 77% missing values","metadata":{}},{"cell_type":"code","source":"df.drop('Cabin',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.190595Z","iopub.execute_input":"2022-08-13T17:59:43.191065Z","iopub.status.idle":"2022-08-13T17:59:43.197088Z","shell.execute_reply.started":"2022-08-13T17:59:43.191039Z","shell.execute_reply":"2022-08-13T17:59:43.195952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'figure.figsize':(12,8)})\nsns.distplot(df['Age'],kde=True,bins=25)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.208644Z","iopub.execute_input":"2022-08-13T17:59:43.209149Z","iopub.status.idle":"2022-08-13T17:59:43.508434Z","shell.execute_reply.started":"2022-08-13T17:59:43.209122Z","shell.execute_reply":"2022-08-13T17:59:43.507467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As the data is not normal,let us make log transformation","metadata":{}},{"cell_type":"markdown","source":"The distribution has become left skewed. So, we will replace missing values with median. At first, let us remove the outliers.","metadata":{}},{"cell_type":"code","source":"sns.boxplot(x=df['Age'])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.510357Z","iopub.execute_input":"2022-08-13T17:59:43.511413Z","iopub.status.idle":"2022-08-13T17:59:43.739736Z","shell.execute_reply.started":"2022-08-13T17:59:43.511359Z","shell.execute_reply":"2022-08-13T17:59:43.738660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"first_quartile = df['Age'].quantile(.25)\nthird_quartile= df['Age'].quantile(.75)\nIQR= third_quartile - first_quartile","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.741600Z","iopub.execute_input":"2022-08-13T17:59:43.742059Z","iopub.status.idle":"2022-08-13T17:59:43.750161Z","shell.execute_reply.started":"2022-08-13T17:59:43.742012Z","shell.execute_reply":"2022-08-13T17:59:43.749040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_boundary = third_quartile - 1.5*IQR","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.753774Z","iopub.execute_input":"2022-08-13T17:59:43.754298Z","iopub.status.idle":"2022-08-13T17:59:43.759817Z","shell.execute_reply.started":"2022-08-13T17:59:43.754202Z","shell.execute_reply":"2022-08-13T17:59:43.758546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.761145Z","iopub.execute_input":"2022-08-13T17:59:43.763426Z","iopub.status.idle":"2022-08-13T17:59:43.775415Z","shell.execute_reply.started":"2022-08-13T17:59:43.763376Z","shell.execute_reply":"2022-08-13T17:59:43.774260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(df[df['Age']<new_boundary].index,axis=0,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.777533Z","iopub.execute_input":"2022-08-13T17:59:43.778247Z","iopub.status.idle":"2022-08-13T17:59:43.786278Z","shell.execute_reply.started":"2022-08-13T17:59:43.778212Z","shell.execute_reply":"2022-08-13T17:59:43.785067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.787733Z","iopub.execute_input":"2022-08-13T17:59:43.788321Z","iopub.status.idle":"2022-08-13T17:59:43.796330Z","shell.execute_reply.started":"2022-08-13T17:59:43.788286Z","shell.execute_reply":"2022-08-13T17:59:43.795313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(x=df['Age'])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:43.797982Z","iopub.execute_input":"2022-08-13T17:59:43.798972Z","iopub.status.idle":"2022-08-13T17:59:44.026909Z","shell.execute_reply.started":"2022-08-13T17:59:43.798936Z","shell.execute_reply":"2022-08-13T17:59:44.025850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:44.028395Z","iopub.execute_input":"2022-08-13T17:59:44.029858Z","iopub.status.idle":"2022-08-13T17:59:44.036787Z","shell.execute_reply.started":"2022-08-13T17:59:44.029820Z","shell.execute_reply":"2022-08-13T17:59:44.035837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'figure.figsize':(12,8)})\nsns.distplot(df['Age'],kde=True,bins=25)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:44.042728Z","iopub.execute_input":"2022-08-13T17:59:44.042986Z","iopub.status.idle":"2022-08-13T17:59:44.646246Z","shell.execute_reply.started":"2022-08-13T17:59:44.042963Z","shell.execute_reply":"2022-08-13T17:59:44.645201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Age']=df['Age'].fillna(df['Age'].median())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:44.650257Z","iopub.execute_input":"2022-08-13T17:59:44.651093Z","iopub.status.idle":"2022-08-13T17:59:44.658262Z","shell.execute_reply.started":"2022-08-13T17:59:44.651053Z","shell.execute_reply":"2022-08-13T17:59:44.657328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t['Age']=df_t['Age'].fillna(df_t['Age'].median())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:44.659798Z","iopub.execute_input":"2022-08-13T17:59:44.660405Z","iopub.status.idle":"2022-08-13T17:59:44.670224Z","shell.execute_reply.started":"2022-08-13T17:59:44.660371Z","shell.execute_reply":"2022-08-13T17:59:44.669090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Embarked']=df['Embarked'].fillna(df['Embarked'].mode())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:44.672993Z","iopub.execute_input":"2022-08-13T17:59:44.674285Z","iopub.status.idle":"2022-08-13T17:59:44.684723Z","shell.execute_reply.started":"2022-08-13T17:59:44.674241Z","shell.execute_reply":"2022-08-13T17:59:44.683801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t['Embarked']=df_t['Embarked'].fillna(df_t['Embarked'].mode())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:44.688698Z","iopub.execute_input":"2022-08-13T17:59:44.690139Z","iopub.status.idle":"2022-08-13T17:59:44.698500Z","shell.execute_reply.started":"2022-08-13T17:59:44.690103Z","shell.execute_reply":"2022-08-13T17:59:44.697477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA 2 <a class=\"anchor\" id=\"sec6\"></a>","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(25, 25))\nfor i, col in enumerate(df.select_dtypes(include=['float64']).columns):\n    ax = plt.subplot(3,2, i+1)\n    sns.histplot(data=df, x=col, ax=ax)\nplt.suptitle('Histogram Plots for all continuous variables')\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:44.699816Z","iopub.execute_input":"2022-08-13T17:59:44.700680Z","iopub.status.idle":"2022-08-13T17:59:45.529858Z","shell.execute_reply.started":"2022-08-13T17:59:44.700646Z","shell.execute_reply":"2022-08-13T17:59:45.528962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(25, 25))\nfor i, col in enumerate(df.select_dtypes(include=['int64']).columns):\n    ax = plt.subplot(3,2, i+1)\n    sns.histplot(data=df, x=col, ax=ax)\nplt.suptitle('Histogram Plots for all continuous variables')\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:45.531364Z","iopub.execute_input":"2022-08-13T17:59:45.532138Z","iopub.status.idle":"2022-08-13T17:59:46.924562Z","shell.execute_reply.started":"2022-08-13T17:59:45.532096Z","shell.execute_reply":"2022-08-13T17:59:46.923578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(25, 25))\nfor i, col in enumerate(df.select_dtypes(include=['object']).columns):\n    ax = plt.subplot(3,2, i+1)\n    sns.histplot(data=df, x=col, ax=ax)\nplt.suptitle('Histogram Plots for all category variables')\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T17:59:46.926158Z","iopub.execute_input":"2022-08-13T17:59:46.926751Z","iopub.status.idle":"2022-08-13T18:00:42.272806Z","shell.execute_reply.started":"2022-08-13T17:59:46.926713Z","shell.execute_reply":"2022-08-13T18:00:42.271855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Fare']=np.sqrt(df['Fare'])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.274344Z","iopub.execute_input":"2022-08-13T18:00:42.274983Z","iopub.status.idle":"2022-08-13T18:00:42.281557Z","shell.execute_reply.started":"2022-08-13T18:00:42.274942Z","shell.execute_reply":"2022-08-13T18:00:42.280490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(x=df['Fare'])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.283235Z","iopub.execute_input":"2022-08-13T18:00:42.283845Z","iopub.status.idle":"2022-08-13T18:00:42.500977Z","shell.execute_reply.started":"2022-08-13T18:00:42.283808Z","shell.execute_reply":"2022-08-13T18:00:42.500088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'figure.figsize':(12,8)})\nsns.distplot(df['Fare'],kde=True,bins=25)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.502294Z","iopub.execute_input":"2022-08-13T18:00:42.502661Z","iopub.status.idle":"2022-08-13T18:00:42.790551Z","shell.execute_reply.started":"2022-08-13T18:00:42.502625Z","shell.execute_reply":"2022-08-13T18:00:42.789591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"first_quartile = df['Fare'].quantile(.25)\nthird_quartile= df['Fare'].quantile(.75)\nIQR= third_quartile - first_quartile","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.792017Z","iopub.execute_input":"2022-08-13T18:00:42.792324Z","iopub.status.idle":"2022-08-13T18:00:42.799457Z","shell.execute_reply.started":"2022-08-13T18:00:42.792296Z","shell.execute_reply":"2022-08-13T18:00:42.798531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_boundary = third_quartile + 2*IQR","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.801065Z","iopub.execute_input":"2022-08-13T18:00:42.801776Z","iopub.status.idle":"2022-08-13T18:00:42.810252Z","shell.execute_reply.started":"2022-08-13T18:00:42.801740Z","shell.execute_reply":"2022-08-13T18:00:42.809072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(df[df['Fare']>new_boundary].index,axis=0,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.811681Z","iopub.execute_input":"2022-08-13T18:00:42.812115Z","iopub.status.idle":"2022-08-13T18:00:42.822438Z","shell.execute_reply.started":"2022-08-13T18:00:42.812081Z","shell.execute_reply":"2022-08-13T18:00:42.821402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.824516Z","iopub.execute_input":"2022-08-13T18:00:42.825275Z","iopub.status.idle":"2022-08-13T18:00:42.836696Z","shell.execute_reply.started":"2022-08-13T18:00:42.825240Z","shell.execute_reply":"2022-08-13T18:00:42.835672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.838529Z","iopub.execute_input":"2022-08-13T18:00:42.838892Z","iopub.status.idle":"2022-08-13T18:00:42.847479Z","shell.execute_reply.started":"2022-08-13T18:00:42.838857Z","shell.execute_reply":"2022-08-13T18:00:42.846400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(x=df['Fare'])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:42.849153Z","iopub.execute_input":"2022-08-13T18:00:42.849737Z","iopub.status.idle":"2022-08-13T18:00:43.062975Z","shell.execute_reply.started":"2022-08-13T18:00:42.849703Z","shell.execute_reply":"2022-08-13T18:00:43.062048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['PassengerId','Name','Ticket'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.064247Z","iopub.execute_input":"2022-08-13T18:00:43.065160Z","iopub.status.idle":"2022-08-13T18:00:43.071764Z","shell.execute_reply.started":"2022-08-13T18:00:43.065123Z","shell.execute_reply":"2022-08-13T18:00:43.070583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t.drop(['PassengerId','Name','Ticket','Cabin'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.079306Z","iopub.execute_input":"2022-08-13T18:00:43.080149Z","iopub.status.idle":"2022-08-13T18:00:43.086312Z","shell.execute_reply.started":"2022-08-13T18:00:43.080112Z","shell.execute_reply":"2022-08-13T18:00:43.085296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.087943Z","iopub.execute_input":"2022-08-13T18:00:43.088559Z","iopub.status.idle":"2022-08-13T18:00:43.098527Z","shell.execute_reply.started":"2022-08-13T18:00:43.088513Z","shell.execute_reply":"2022-08-13T18:00:43.097491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.101132Z","iopub.execute_input":"2022-08-13T18:00:43.102815Z","iopub.status.idle":"2022-08-13T18:00:43.116308Z","shell.execute_reply.started":"2022-08-13T18:00:43.102779Z","shell.execute_reply":"2022-08-13T18:00:43.114781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.118151Z","iopub.execute_input":"2022-08-13T18:00:43.119573Z","iopub.status.idle":"2022-08-13T18:00:43.133359Z","shell.execute_reply.started":"2022-08-13T18:00:43.119545Z","shell.execute_reply":"2022-08-13T18:00:43.132462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Join","metadata":{}},{"cell_type":"code","source":"df_main=pd.concat([df,df_t],axis=0)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.134728Z","iopub.execute_input":"2022-08-13T18:00:43.135354Z","iopub.status.idle":"2022-08-13T18:00:43.143352Z","shell.execute_reply.started":"2022-08-13T18:00:43.135304Z","shell.execute_reply":"2022-08-13T18:00:43.142485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.145114Z","iopub.execute_input":"2022-08-13T18:00:43.146047Z","iopub.status.idle":"2022-08-13T18:00:43.159623Z","shell.execute_reply.started":"2022-08-13T18:00:43.145996Z","shell.execute_reply":"2022-08-13T18:00:43.158622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.161306Z","iopub.execute_input":"2022-08-13T18:00:43.161692Z","iopub.status.idle":"2022-08-13T18:00:43.172346Z","shell.execute_reply.started":"2022-08-13T18:00:43.161652Z","shell.execute_reply":"2022-08-13T18:00:43.170929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Label Encoding <a class=\"anchor\" id=\"sec7\"></a>","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:00:43.174010Z","iopub.execute_input":"2022-08-13T18:00:43.174771Z","iopub.status.idle":"2022-08-13T18:00:43.181299Z","shell.execute_reply.started":"2022-08-13T18:00:43.174737Z","shell.execute_reply":"2022-08-13T18:00:43.180135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()\nencoded = le.fit_transform(np.ravel(df_main['Embarked'])) ","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:07.943400Z","iopub.execute_input":"2022-08-13T18:02:07.943786Z","iopub.status.idle":"2022-08-13T18:02:07.952436Z","shell.execute_reply.started":"2022-08-13T18:02:07.943755Z","shell.execute_reply":"2022-08-13T18:02:07.951224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"encoded","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:07.978468Z","iopub.execute_input":"2022-08-13T18:02:07.978753Z","iopub.status.idle":"2022-08-13T18:02:07.989284Z","shell.execute_reply.started":"2022-08-13T18:02:07.978728Z","shell.execute_reply":"2022-08-13T18:02:07.988298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main['Embarked']=encoded","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:08.028098Z","iopub.execute_input":"2022-08-13T18:02:08.028369Z","iopub.status.idle":"2022-08-13T18:02:08.034372Z","shell.execute_reply.started":"2022-08-13T18:02:08.028344Z","shell.execute_reply":"2022-08-13T18:02:08.033204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()\nencoded = le.fit_transform(np.ravel(df_main['Sex'])) ","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:37.024732Z","iopub.execute_input":"2022-08-13T18:02:37.025389Z","iopub.status.idle":"2022-08-13T18:02:37.031689Z","shell.execute_reply.started":"2022-08-13T18:02:37.025355Z","shell.execute_reply":"2022-08-13T18:02:37.029528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main['Sex']=encoded","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:37.033471Z","iopub.execute_input":"2022-08-13T18:02:37.034620Z","iopub.status.idle":"2022-08-13T18:02:37.043792Z","shell.execute_reply.started":"2022-08-13T18:02:37.034568Z","shell.execute_reply":"2022-08-13T18:02:37.042816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:37.045456Z","iopub.execute_input":"2022-08-13T18:02:37.046281Z","iopub.status.idle":"2022-08-13T18:02:37.060977Z","shell.execute_reply.started":"2022-08-13T18:02:37.046245Z","shell.execute_reply":"2022-08-13T18:02:37.059707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:37.068137Z","iopub.execute_input":"2022-08-13T18:02:37.069061Z","iopub.status.idle":"2022-08-13T18:02:37.078646Z","shell.execute_reply.started":"2022-08-13T18:02:37.069022Z","shell.execute_reply":"2022-08-13T18:02:37.077331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main['Fare']=df_main['Fare'].fillna(df_t['Fare'].median())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:02:37.141558Z","iopub.execute_input":"2022-08-13T18:02:37.143564Z","iopub.status.idle":"2022-08-13T18:02:37.149543Z","shell.execute_reply.started":"2022-08-13T18:02:37.143532Z","shell.execute_reply":"2022-08-13T18:02:37.148437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_main['Embarked']=df_main['Embarked'].fillna(df_t['Embarked'].mode())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:05.696392Z","iopub.execute_input":"2022-08-13T18:03:05.696782Z","iopub.status.idle":"2022-08-13T18:03:05.703918Z","shell.execute_reply.started":"2022-08-13T18:03:05.696749Z","shell.execute_reply":"2022-08-13T18:03:05.702851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=df_main.iloc[:784,:]\ntest=df_main.iloc[784:,:]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.683228Z","iopub.execute_input":"2022-08-13T18:03:12.683674Z","iopub.status.idle":"2022-08-13T18:03:12.689357Z","shell.execute_reply.started":"2022-08-13T18:03:12.683639Z","shell.execute_reply":"2022-08-13T18:03:12.688255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.806819Z","iopub.execute_input":"2022-08-13T18:03:12.807426Z","iopub.status.idle":"2022-08-13T18:03:12.822341Z","shell.execute_reply.started":"2022-08-13T18:03:12.807383Z","shell.execute_reply":"2022-08-13T18:03:12.821150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.825227Z","iopub.execute_input":"2022-08-13T18:03:12.826109Z","iopub.status.idle":"2022-08-13T18:03:12.836130Z","shell.execute_reply.started":"2022-08-13T18:03:12.826071Z","shell.execute_reply":"2022-08-13T18:03:12.835081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train-Test Split <a class=\"anchor\" id=\"sec8\"></a>","metadata":{}},{"cell_type":"code","source":"x = train.drop(\"Survived\",axis=1)\ny = train[[\"Survived\"]]\n\nfrom sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.20,random_state=49)\nprint(\"x_train :\",x_train.shape)\nprint(\"x_test :\",x_test.shape)\nprint(\"y_train :\",y_train.shape)\nprint(\"y_test :\",y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.838670Z","iopub.execute_input":"2022-08-13T18:03:12.839752Z","iopub.status.idle":"2022-08-13T18:03:12.851254Z","shell.execute_reply.started":"2022-08-13T18:03:12.839716Z","shell.execute_reply":"2022-08-13T18:03:12.850333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.854017Z","iopub.execute_input":"2022-08-13T18:03:12.854852Z","iopub.status.idle":"2022-08-13T18:03:12.868469Z","shell.execute_reply.started":"2022-08-13T18:03:12.854815Z","shell.execute_reply":"2022-08-13T18:03:12.867561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.896837Z","iopub.execute_input":"2022-08-13T18:03:12.897378Z","iopub.status.idle":"2022-08-13T18:03:12.906915Z","shell.execute_reply.started":"2022-08-13T18:03:12.897342Z","shell.execute_reply":"2022-08-13T18:03:12.905934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"# Prediction <a class=\"anchor\" id=\"sec9\"></a>","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nclf=LogisticRegression()\nclf.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.909024Z","iopub.execute_input":"2022-08-13T18:03:12.909496Z","iopub.status.idle":"2022-08-13T18:03:12.948451Z","shell.execute_reply.started":"2022-08-13T18:03:12.909460Z","shell.execute_reply":"2022-08-13T18:03:12.947586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=clf.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.950284Z","iopub.execute_input":"2022-08-13T18:03:12.950638Z","iopub.status.idle":"2022-08-13T18:03:12.956704Z","shell.execute_reply.started":"2022-08-13T18:03:12.950591Z","shell.execute_reply":"2022-08-13T18:03:12.955747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import metrics\nprint(\"Logistic Regression accuracy(in %):\", metrics.accuracy_score(y_test, y_pred)*100)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:12:29.876045Z","iopub.execute_input":"2022-08-13T18:12:29.876434Z","iopub.status.idle":"2022-08-13T18:12:29.883541Z","shell.execute_reply.started":"2022-08-13T18:12:29.876396Z","shell.execute_reply":"2022-08-13T18:12:29.882542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=test.drop(\"Survived\",axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:12.972664Z","iopub.execute_input":"2022-08-13T18:03:12.973259Z","iopub.status.idle":"2022-08-13T18:03:12.979772Z","shell.execute_reply.started":"2022-08-13T18:03:12.973214Z","shell.execute_reply":"2022-08-13T18:03:12.978889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.008810Z","iopub.execute_input":"2022-08-13T18:03:13.009363Z","iopub.status.idle":"2022-08-13T18:03:13.016052Z","shell.execute_reply.started":"2022-08-13T18:03:13.009329Z","shell.execute_reply":"2022-08-13T18:03:13.015045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds1=clf.predict(x)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.047794Z","iopub.execute_input":"2022-08-13T18:03:13.048054Z","iopub.status.idle":"2022-08-13T18:03:13.053866Z","shell.execute_reply.started":"2022-08-13T18:03:13.048030Z","shell.execute_reply":"2022-08-13T18:03:13.052844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(preds1)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.344443Z","iopub.execute_input":"2022-08-13T18:03:13.345227Z","iopub.status.idle":"2022-08-13T18:03:13.352070Z","shell.execute_reply.started":"2022-08-13T18:03:13.345182Z","shell.execute_reply":"2022-08-13T18:03:13.350934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub=pd.read_csv(\"../input/titanic/gender_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.354339Z","iopub.execute_input":"2022-08-13T18:03:13.355526Z","iopub.status.idle":"2022-08-13T18:03:13.364766Z","shell.execute_reply.started":"2022-08-13T18:03:13.355419Z","shell.execute_reply":"2022-08-13T18:03:13.363847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.366560Z","iopub.execute_input":"2022-08-13T18:03:13.367679Z","iopub.status.idle":"2022-08-13T18:03:13.376424Z","shell.execute_reply.started":"2022-08-13T18:03:13.367643Z","shell.execute_reply":"2022-08-13T18:03:13.375504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.378096Z","iopub.execute_input":"2022-08-13T18:03:13.378752Z","iopub.status.idle":"2022-08-13T18:03:13.388294Z","shell.execute_reply.started":"2022-08-13T18:03:13.378717Z","shell.execute_reply":"2022-08-13T18:03:13.387280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub['Survived']=preds1","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.392216Z","iopub.execute_input":"2022-08-13T18:03:13.393196Z","iopub.status.idle":"2022-08-13T18:03:13.398356Z","shell.execute_reply.started":"2022-08-13T18:03:13.393151Z","shell.execute_reply":"2022-08-13T18:03:13.397279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.400489Z","iopub.execute_input":"2022-08-13T18:03:13.401382Z","iopub.status.idle":"2022-08-13T18:03:13.431141Z","shell.execute_reply.started":"2022-08-13T18:03:13.401341Z","shell.execute_reply":"2022-08-13T18:03:13.430192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub['Survived'].unique","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.433303Z","iopub.execute_input":"2022-08-13T18:03:13.434037Z","iopub.status.idle":"2022-08-13T18:03:13.491146Z","shell.execute_reply.started":"2022-08-13T18:03:13.434001Z","shell.execute_reply":"2022-08-13T18:03:13.489568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.to_csv('TitanicLog2.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T18:03:13.493007Z","iopub.execute_input":"2022-08-13T18:03:13.494264Z","iopub.status.idle":"2022-08-13T18:03:13.505658Z","shell.execute_reply.started":"2022-08-13T18:03:13.494222Z","shell.execute_reply":"2022-08-13T18:03:13.504462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* To be continued...Some correction are required to predict with better accuracy","metadata":{}}]}