{"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":"import numpy as np\nimport pandas as pd\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:26.817345Z","iopub.execute_input":"2022-08-02T11:24:26.818225Z","iopub.status.idle":"2022-08-02T11:24:26.825128Z","shell.execute_reply.started":"2022-08-02T11:24:26.818174Z","shell.execute_reply":"2022-08-02T11:24:26.823821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set=pd.read_csv(\"../input/titanic/train.csv\")\ntest_set=pd.read_csv(\"../input/titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:26.849300Z","iopub.execute_input":"2022-08-02T11:24:26.849857Z","iopub.status.idle":"2022-08-02T11:24:26.870666Z","shell.execute_reply.started":"2022-08-02T11:24:26.849813Z","shell.execute_reply":"2022-08-02T11:24:26.869295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:26.888788Z","iopub.execute_input":"2022-08-02T11:24:26.889679Z","iopub.status.idle":"2022-08-02T11:24:26.913633Z","shell.execute_reply.started":"2022-08-02T11:24:26.889621Z","shell.execute_reply":"2022-08-02T11:24:26.912192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:26.916302Z","iopub.execute_input":"2022-08-02T11:24:26.916870Z","iopub.status.idle":"2022-08-02T11:24:26.939843Z","shell.execute_reply.started":"2022-08-02T11:24:26.916815Z","shell.execute_reply":"2022-08-02T11:24:26.938513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:26.941728Z","iopub.execute_input":"2022-08-02T11:24:26.942923Z","iopub.status.idle":"2022-08-02T11:24:26.956457Z","shell.execute_reply.started":"2022-08-02T11:24:26.942877Z","shell.execute_reply":"2022-08-02T11:24:26.955373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:26.958472Z","iopub.execute_input":"2022-08-02T11:24:26.959161Z","iopub.status.idle":"2022-08-02T11:24:26.983600Z","shell.execute_reply.started":"2022-08-02T11:24:26.959115Z","shell.execute_reply":"2022-08-02T11:24:26.981932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.drop([\"Name\",\"Ticket\",\"Fare\",\"Cabin\"],axis=1,inplace=True)\ntrain_set","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:26.998787Z","iopub.execute_input":"2022-08-02T11:24:26.999682Z","iopub.status.idle":"2022-08-02T11:24:27.024665Z","shell.execute_reply.started":"2022-08-02T11:24:26.999619Z","shell.execute_reply":"2022-08-02T11:24:27.023162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.031452Z","iopub.execute_input":"2022-08-02T11:24:27.032360Z","iopub.status.idle":"2022-08-02T11:24:27.043954Z","shell.execute_reply.started":"2022-08-02T11:24:27.032311Z","shell.execute_reply":"2022-08-02T11:24:27.042661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.dropna(inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.053264Z","iopub.execute_input":"2022-08-02T11:24:27.054551Z","iopub.status.idle":"2022-08-02T11:24:27.065182Z","shell.execute_reply.started":"2022-08-02T11:24:27.054490Z","shell.execute_reply":"2022-08-02T11:24:27.063752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.076970Z","iopub.execute_input":"2022-08-02T11:24:27.077486Z","iopub.status.idle":"2022-08-02T11:24:27.088906Z","shell.execute_reply.started":"2022-08-02T11:24:27.077443Z","shell.execute_reply":"2022-08-02T11:24:27.087798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.100151Z","iopub.execute_input":"2022-08-02T11:24:27.101379Z","iopub.status.idle":"2022-08-02T11:24:27.109153Z","shell.execute_reply.started":"2022-08-02T11:24:27.101320Z","shell.execute_reply":"2022-08-02T11:24:27.107812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.121188Z","iopub.execute_input":"2022-08-02T11:24:27.121867Z","iopub.status.idle":"2022-08-02T11:24:27.146063Z","shell.execute_reply.started":"2022-08-02T11:24:27.121820Z","shell.execute_reply":"2022-08-02T11:24:27.144179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le=LabelEncoder()\ntrain_set[\"Sex\"]=le.fit_transform(train_set[\"Sex\"])\ntrain_set[\"Embarked\"]=le.fit_transform(train_set[\"Embarked\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.183148Z","iopub.execute_input":"2022-08-02T11:24:27.184070Z","iopub.status.idle":"2022-08-02T11:24:27.194929Z","shell.execute_reply.started":"2022-08-02T11:24:27.184019Z","shell.execute_reply":"2022-08-02T11:24:27.193650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.219647Z","iopub.execute_input":"2022-08-02T11:24:27.220638Z","iopub.status.idle":"2022-08-02T11:24:27.239127Z","shell.execute_reply.started":"2022-08-02T11:24:27.220583Z","shell.execute_reply":"2022-08-02T11:24:27.237647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=train_set.drop(\"Survived\",axis=1)\ny=train_set[\"Survived\"]","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.241845Z","iopub.execute_input":"2022-08-02T11:24:27.242912Z","iopub.status.idle":"2022-08-02T11:24:27.249121Z","shell.execute_reply.started":"2022-08-02T11:24:27.242853Z","shell.execute_reply":"2022-08-02T11:24:27.248116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr=LogisticRegression(penalty=\"l2\",C=1.0,solver=\"liblinear\")\nlr.fit(X,y)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.251117Z","iopub.execute_input":"2022-08-02T11:24:27.252143Z","iopub.status.idle":"2022-08-02T11:24:27.277715Z","shell.execute_reply.started":"2022-08-02T11:24:27.252104Z","shell.execute_reply":"2022-08-02T11:24:27.276090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.279967Z","iopub.execute_input":"2022-08-02T11:24:27.281251Z","iopub.status.idle":"2022-08-02T11:24:27.288301Z","shell.execute_reply.started":"2022-08-02T11:24:27.281209Z","shell.execute_reply":"2022-08-02T11:24:27.286889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.290682Z","iopub.execute_input":"2022-08-02T11:24:27.291610Z","iopub.status.idle":"2022-08-02T11:24:27.318430Z","shell.execute_reply.started":"2022-08-02T11:24:27.291535Z","shell.execute_reply":"2022-08-02T11:24:27.317468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set.dropna(inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.320715Z","iopub.execute_input":"2022-08-02T11:24:27.321311Z","iopub.status.idle":"2022-08-02T11:24:27.330374Z","shell.execute_reply.started":"2022-08-02T11:24:27.321273Z","shell.execute_reply":"2022-08-02T11:24:27.328837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set.drop([\"Name\",\"Ticket\",\"Fare\",\"Cabin\"],axis=1,inplace=True)\ntest_set","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.332685Z","iopub.execute_input":"2022-08-02T11:24:27.333509Z","iopub.status.idle":"2022-08-02T11:24:27.364884Z","shell.execute_reply.started":"2022-08-02T11:24:27.333456Z","shell.execute_reply":"2022-08-02T11:24:27.363019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le=LabelEncoder()\ntest_set[\"Sex\"]=le.fit_transform(test_set[\"Sex\"])\ntest_set[\"Embarked\"]=le.fit_transform(test_set[\"Embarked\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.367081Z","iopub.execute_input":"2022-08-02T11:24:27.368311Z","iopub.status.idle":"2022-08-02T11:24:27.379726Z","shell.execute_reply.started":"2022-08-02T11:24:27.368257Z","shell.execute_reply":"2022-08-02T11:24:27.378402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.381430Z","iopub.execute_input":"2022-08-02T11:24:27.382255Z","iopub.status.idle":"2022-08-02T11:24:27.412953Z","shell.execute_reply.started":"2022-08-02T11:24:27.382211Z","shell.execute_reply":"2022-08-02T11:24:27.411812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set.isna().sum()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.415690Z","iopub.execute_input":"2022-08-02T11:24:27.416982Z","iopub.status.idle":"2022-08-02T11:24:27.433809Z","shell.execute_reply.started":"2022-08-02T11:24:27.416920Z","shell.execute_reply":"2022-08-02T11:24:27.432769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_value=lr.predict(test_set)","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.434964Z","iopub.execute_input":"2022-08-02T11:24:27.435968Z","iopub.status.idle":"2022-08-02T11:24:27.449376Z","shell.execute_reply.started":"2022-08-02T11:24:27.435930Z","shell.execute_reply":"2022-08-02T11:24:27.448175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.450645Z","iopub.execute_input":"2022-08-02T11:24:27.451680Z","iopub.status.idle":"2022-08-02T11:24:27.477588Z","shell.execute_reply.started":"2022-08-02T11:24:27.451636Z","shell.execute_reply":"2022-08-02T11:24:27.476286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result=pd.DataFrame({\"PassengerId\":test_set[\"PassengerId\"],\"PredictedValue\":predicted_value})\nresult","metadata":{"execution":{"iopub.status.busy":"2022-08-02T11:24:27.479189Z","iopub.execute_input":"2022-08-02T11:24:27.480363Z","iopub.status.idle":"2022-08-02T11:24:27.503684Z","shell.execute_reply.started":"2022-08-02T11:24:27.480292Z","shell.execute_reply":"2022-08-02T11:24:27.502679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}