{"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-10T16:59:26.249617Z","iopub.execute_input":"2022-07-10T16:59:26.250320Z","iopub.status.idle":"2022-07-10T16:59:26.258102Z","shell.execute_reply.started":"2022-07-10T16:59:26.250268Z","shell.execute_reply":"2022-07-10T16:59:26.257181Z"},"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-10T16:59:52.386026Z","iopub.execute_input":"2022-07-10T16:59:52.386507Z","iopub.status.idle":"2022-07-10T16:59:53.025249Z","shell.execute_reply.started":"2022-07-10T16:59:52.386466Z","shell.execute_reply":"2022-07-10T16:59:53.024088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"../input/titanic/train.csv\")\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T17:00:28.113126Z","iopub.execute_input":"2022-07-10T17:00:28.114071Z","iopub.status.idle":"2022-07-10T17:00:28.142703Z","shell.execute_reply.started":"2022-07-10T17:00:28.114029Z","shell.execute_reply":"2022-07-10T17:00:28.141943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train.isnull(),yticklabels=False,cbar=False,cmap=\"viridis\")\n","metadata":{"execution":{"iopub.status.busy":"2022-07-10T17:02:56.573751Z","iopub.execute_input":"2022-07-10T17:02:56.574239Z","iopub.status.idle":"2022-07-10T17:02:56.766029Z","shell.execute_reply.started":"2022-07-10T17:02:56.574199Z","shell.execute_reply":"2022-07-10T17:02:56.764759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x=\"Survived\",hue=\"Sex\",data=train)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T17:14:41.102579Z","iopub.execute_input":"2022-07-10T17:14:41.103164Z","iopub.status.idle":"2022-07-10T17:14:41.300492Z","shell.execute_reply.started":"2022-07-10T17:14:41.103113Z","shell.execute_reply":"2022-07-10T17:14:41.299046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x=\"Survived\",hue=\"Pclass\",data=train)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T17:15:41.807540Z","iopub.execute_input":"2022-07-10T17:15:41.808869Z","iopub.status.idle":"2022-07-10T17:15:42.003284Z","shell.execute_reply.started":"2022-07-10T17:15:41.808818Z","shell.execute_reply":"2022-07-10T17:15:42.002040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(train[\"Age\"].dropna())","metadata":{"execution":{"iopub.status.busy":"2022-07-10T17:17:34.492476Z","iopub.execute_input":"2022-07-10T17:17:34.492976Z","iopub.status.idle":"2022-07-10T17:17:34.724705Z","shell.execute_reply.started":"2022-07-10T17:17:34.492933Z","shell.execute_reply":"2022-07-10T17:17:34.723832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(train[\"Fare\"],bins=10)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T17:20:56.592912Z","iopub.execute_input":"2022-07-10T17:20:56.593392Z","iopub.status.idle":"2022-07-10T17:20:56.878808Z","shell.execute_reply.started":"2022-07-10T17:20:56.593352Z","shell.execute_reply":"2022-07-10T17:20:56.877628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Creating interactive histograms\nimport cufflinks as cf\ncf.go_offline()\ntrain[\"Fare\"].iplot(kind=\"hist\")","metadata":{"execution":{"iopub.status.busy":"2022-07-10T17:22:37.767990Z","iopub.execute_input":"2022-07-10T17:22:37.768401Z","iopub.status.idle":"2022-07-10T17:22:38.589179Z","shell.execute_reply.started":"2022-07-10T17:22:37.768368Z","shell.execute_reply":"2022-07-10T17:22:38.587912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def impute_age(cols):\n    Age=cols[0]\n    Pclass=cols[1]\n    if pd.isnull(Age):\n        if Pclass==1:\n            return 37\n        elif Pclass==2:\n            return 29\n        else:\n            return 24\n    else:\n            return Age","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:02:40.672604Z","iopub.execute_input":"2022-07-10T18:02:40.673139Z","iopub.status.idle":"2022-07-10T18:02:40.679756Z","shell.execute_reply.started":"2022-07-10T18:02:40.673094Z","shell.execute_reply":"2022-07-10T18:02:40.678803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[\"Age\"]=train[[\"Age\",\"Pclass\"]].apply(impute_age,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:03:31.536562Z","iopub.execute_input":"2022-07-10T18:03:31.537021Z","iopub.status.idle":"2022-07-10T18:03:31.556643Z","shell.execute_reply.started":"2022-07-10T18:03:31.536981Z","shell.execute_reply":"2022-07-10T18:03:31.555155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train.isnull())","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:05:09.555669Z","iopub.execute_input":"2022-07-10T18:05:09.556429Z","iopub.status.idle":"2022-07-10T18:05:09.928548Z","shell.execute_reply.started":"2022-07-10T18:05:09.556375Z","shell.execute_reply":"2022-07-10T18:05:09.927302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop(\"Cabin\",axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:07:12.223450Z","iopub.execute_input":"2022-07-10T18:07:12.223961Z","iopub.status.idle":"2022-07-10T18:07:12.261347Z","shell.execute_reply.started":"2022-07-10T18:07:12.223920Z","shell.execute_reply":"2022-07-10T18:07:12.259601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dropna(inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:07:20.970636Z","iopub.execute_input":"2022-07-10T18:07:20.971109Z","iopub.status.idle":"2022-07-10T18:07:20.981109Z","shell.execute_reply.started":"2022-07-10T18:07:20.971070Z","shell.execute_reply":"2022-07-10T18:07:20.980184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sex=pd.get_dummies(train[\"Sex\"],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:13:48.021359Z","iopub.execute_input":"2022-07-10T18:13:48.021892Z","iopub.status.idle":"2022-07-10T18:13:48.034425Z","shell.execute_reply.started":"2022-07-10T18:13:48.021835Z","shell.execute_reply":"2022-07-10T18:13:48.033248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"embark=pd.get_dummies(train[\"Embarked\"],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:13:50.437644Z","iopub.execute_input":"2022-07-10T18:13:50.438760Z","iopub.status.idle":"2022-07-10T18:13:50.445039Z","shell.execute_reply.started":"2022-07-10T18:13:50.438712Z","shell.execute_reply":"2022-07-10T18:13:50.443952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.concat([train,sex,embark],axis=1)\ntrain.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:14:08.076591Z","iopub.execute_input":"2022-07-10T18:14:08.077147Z","iopub.status.idle":"2022-07-10T18:14:08.102750Z","shell.execute_reply.started":"2022-07-10T18:14:08.077088Z","shell.execute_reply":"2022-07-10T18:14:08.101545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop([\"Sex\",\"Embarked\",\"Name\",\"Ticket\"],axis=1,inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:15:24.376802Z","iopub.execute_input":"2022-07-10T18:15:24.377282Z","iopub.status.idle":"2022-07-10T18:15:24.411314Z","shell.execute_reply.started":"2022-07-10T18:15:24.377245Z","shell.execute_reply":"2022-07-10T18:15:24.409404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:15:36.241392Z","iopub.execute_input":"2022-07-10T18:15:36.241822Z","iopub.status.idle":"2022-07-10T18:15:36.265269Z","shell.execute_reply.started":"2022-07-10T18:15:36.241789Z","shell.execute_reply":"2022-07-10T18:15:36.264097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.T.drop_duplicates().T","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:17:08.663023Z","iopub.execute_input":"2022-07-10T18:17:08.663539Z","iopub.status.idle":"2022-07-10T18:17:08.772541Z","shell.execute_reply.started":"2022-07-10T18:17:08.663496Z","shell.execute_reply":"2022-07-10T18:17:08.771442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop(\"PassengerId\",axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:18:23.229553Z","iopub.execute_input":"2022-07-10T18:18:23.230175Z","iopub.status.idle":"2022-07-10T18:18:23.237190Z","shell.execute_reply.started":"2022-07-10T18:18:23.230125Z","shell.execute_reply":"2022-07-10T18:18:23.235945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:18:25.379372Z","iopub.execute_input":"2022-07-10T18:18:25.379800Z","iopub.status.idle":"2022-07-10T18:18:25.397389Z","shell.execute_reply.started":"2022-07-10T18:18:25.379758Z","shell.execute_reply":"2022-07-10T18:18:25.396408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train.drop(\"Survived\",axis=1)\ny=train[\"Survived\"]","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:26:28.877548Z","iopub.execute_input":"2022-07-10T18:26:28.878021Z","iopub.status.idle":"2022-07-10T18:26:28.884822Z","shell.execute_reply.started":"2022-07-10T18:26:28.877982Z","shell.execute_reply":"2022-07-10T18:26:28.883904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:28:05.747802Z","iopub.execute_input":"2022-07-10T18:28:05.748329Z","iopub.status.idle":"2022-07-10T18:28:05.852852Z","shell.execute_reply.started":"2022-07-10T18:28:05.748290Z","shell.execute_reply":"2022-07-10T18:28:05.851700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=101)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:33:42.006315Z","iopub.execute_input":"2022-07-10T18:33:42.006754Z","iopub.status.idle":"2022-07-10T18:33:42.014811Z","shell.execute_reply.started":"2022-07-10T18:33:42.006719Z","shell.execute_reply":"2022-07-10T18:33:42.013835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:34:23.750535Z","iopub.execute_input":"2022-07-10T18:34:23.751032Z","iopub.status.idle":"2022-07-10T18:34:23.756812Z","shell.execute_reply.started":"2022-07-10T18:34:23.750991Z","shell.execute_reply":"2022-07-10T18:34:23.755699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logmodel=LogisticRegression(max_iter=1000)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:04:27.672220Z","iopub.execute_input":"2022-07-10T19:04:27.672737Z","iopub.status.idle":"2022-07-10T19:04:27.679743Z","shell.execute_reply.started":"2022-07-10T19:04:27.672691Z","shell.execute_reply":"2022-07-10T19:04:27.677994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logmodel.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:04:29.788009Z","iopub.execute_input":"2022-07-10T19:04:29.789137Z","iopub.status.idle":"2022-07-10T19:04:29.849141Z","shell.execute_reply.started":"2022-07-10T19:04:29.789090Z","shell.execute_reply":"2022-07-10T19:04:29.847979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions=logmodel.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:04:53.672382Z","iopub.execute_input":"2022-07-10T19:04:53.672847Z","iopub.status.idle":"2022-07-10T19:04:53.681647Z","shell.execute_reply.started":"2022-07-10T19:04:53.672809Z","shell.execute_reply":"2022-07-10T19:04:53.680577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report\nprint(classification_report(y_test,predictions))","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:06:36.839441Z","iopub.execute_input":"2022-07-10T19:06:36.840262Z","iopub.status.idle":"2022-07-10T19:06:36.856187Z","shell.execute_reply.started":"2022-07-10T19:06:36.840201Z","shell.execute_reply":"2022-07-10T19:06:36.855110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}