{"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\ntrain=pd.read_csv(\"../input/titanic/train.csv\")\ntrain.head()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-17T12:25:21.862754Z","iopub.execute_input":"2022-07-17T12:25:21.863319Z","iopub.status.idle":"2022-07-17T12:25:21.895106Z","shell.execute_reply.started":"2022-07-17T12:25:21.863243Z","shell.execute_reply":"2022-07-17T12:25:21.893823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:21.897567Z","iopub.execute_input":"2022-07-17T12:25:21.898354Z","iopub.status.idle":"2022-07-17T12:25:21.910812Z","shell.execute_reply.started":"2022-07-17T12:25:21.898300Z","shell.execute_reply":"2022-07-17T12:25:21.909328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Age'].fillna(value=train['Age'].mean(),inplace=True)\ntrain['Embarked'].fillna(value=\"S\",inplace = True)\ntrain.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:21.913260Z","iopub.execute_input":"2022-07-17T12:25:21.914302Z","iopub.status.idle":"2022-07-17T12:25:21.933816Z","shell.execute_reply.started":"2022-07-17T12:25:21.914233Z","shell.execute_reply":"2022-07-17T12:25:21.932652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col_to_use=['Survived','Sex','Age','Fare','Embarked','Pclass','Parch','SibSp']\ntrain=train[col_to_use]\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:21.937483Z","iopub.execute_input":"2022-07-17T12:25:21.938623Z","iopub.status.idle":"2022-07-17T12:25:21.959121Z","shell.execute_reply.started":"2022-07-17T12:25:21.938564Z","shell.execute_reply":"2022-07-17T12:25:21.958337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.get_dummies(train,columns=['Embarked','Sex','Pclass'])\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:21.960520Z","iopub.execute_input":"2022-07-17T12:25:21.962042Z","iopub.status.idle":"2022-07-17T12:25:21.986860Z","shell.execute_reply.started":"2022-07-17T12:25:21.961991Z","shell.execute_reply":"2022-07-17T12:25:21.985654Z"},"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-17T12:25:21.988260Z","iopub.execute_input":"2022-07-17T12:25:21.988899Z","iopub.status.idle":"2022-07-17T12:25:21.997058Z","shell.execute_reply.started":"2022-07-17T12:25:21.988863Z","shell.execute_reply":"2022-07-17T12:25:21.995815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection  import train_test_split\ntrain_X,test_X, train_y, test_y = train_test_split(x,y, test_size=0.4, random_state=2)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:21.998946Z","iopub.execute_input":"2022-07-17T12:25:21.999875Z","iopub.status.idle":"2022-07-17T12:25:22.524235Z","shell.execute_reply.started":"2022-07-17T12:25:21.999827Z","shell.execute_reply":"2022-07-17T12:25:22.522811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nclassifier = LogisticRegression(random_state = 0)\nclassifier.fit(train_X, train_y)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.526163Z","iopub.execute_input":"2022-07-17T12:25:22.526661Z","iopub.status.idle":"2022-07-17T12:25:22.594342Z","shell.execute_reply.started":"2022-07-17T12:25:22.526612Z","shell.execute_reply":"2022-07-17T12:25:22.593050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier.score(train_X, train_y)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.595943Z","iopub.execute_input":"2022-07-17T12:25:22.596350Z","iopub.status.idle":"2022-07-17T12:25:22.608471Z","shell.execute_reply.started":"2022-07-17T12:25:22.596310Z","shell.execute_reply":"2022-07-17T12:25:22.607408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier.score(test_X, test_y)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.611547Z","iopub.execute_input":"2022-07-17T12:25:22.611929Z","iopub.status.idle":"2022-07-17T12:25:22.623031Z","shell.execute_reply.started":"2022-07-17T12:25:22.611891Z","shell.execute_reply":"2022-07-17T12:25:22.621455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=pd.read_csv(\"../input/titanic/test.csv\")\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.624560Z","iopub.execute_input":"2022-07-17T12:25:22.624909Z","iopub.status.idle":"2022-07-17T12:25:22.654016Z","shell.execute_reply.started":"2022-07-17T12:25:22.624879Z","shell.execute_reply":"2022-07-17T12:25:22.652854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col_to_use=['Sex','Age','Fare','Embarked','Pclass','Parch','SibSp']\ntesty=test[col_to_use]\ntesty.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.655628Z","iopub.execute_input":"2022-07-17T12:25:22.656412Z","iopub.status.idle":"2022-07-17T12:25:22.673040Z","shell.execute_reply.started":"2022-07-17T12:25:22.656371Z","shell.execute_reply":"2022-07-17T12:25:22.671963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testy=pd.get_dummies(testy,columns=['Embarked','Sex','Pclass'])\ntesty.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.674243Z","iopub.execute_input":"2022-07-17T12:25:22.675264Z","iopub.status.idle":"2022-07-17T12:25:22.699815Z","shell.execute_reply.started":"2022-07-17T12:25:22.675224Z","shell.execute_reply":"2022-07-17T12:25:22.698799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testy.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.701059Z","iopub.execute_input":"2022-07-17T12:25:22.701608Z","iopub.status.idle":"2022-07-17T12:25:22.711634Z","shell.execute_reply.started":"2022-07-17T12:25:22.701567Z","shell.execute_reply":"2022-07-17T12:25:22.710470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testy['Age'].fillna(value=testy['Age'].mean(),inplace=True)\ntesty['Fare'].fillna(value=testy['Fare'].mean(),inplace=True)\ntesty.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.713092Z","iopub.execute_input":"2022-07-17T12:25:22.714105Z","iopub.status.idle":"2022-07-17T12:25:22.726847Z","shell.execute_reply.started":"2022-07-17T12:25:22.714066Z","shell.execute_reply":"2022-07-17T12:25:22.725901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=classifier.predict(testy)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.728407Z","iopub.execute_input":"2022-07-17T12:25:22.729042Z","iopub.status.idle":"2022-07-17T12:25:22.742862Z","shell.execute_reply.started":"2022-07-17T12:25:22.729002Z","shell.execute_reply":"2022-07-17T12:25:22.741372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col=['PassengerId']\nsubmission=test[col]\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.744676Z","iopub.execute_input":"2022-07-17T12:25:22.745709Z","iopub.status.idle":"2022-07-17T12:25:22.759584Z","shell.execute_reply.started":"2022-07-17T12:25:22.745656Z","shell.execute_reply":"2022-07-17T12:25:22.758530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['Survived']=y_pred\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.761195Z","iopub.execute_input":"2022-07-17T12:25:22.761820Z","iopub.status.idle":"2022-07-17T12:25:22.779619Z","shell.execute_reply.started":"2022-07-17T12:25:22.761781Z","shell.execute_reply":"2022-07-17T12:25:22.778319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T12:25:22.781446Z","iopub.execute_input":"2022-07-17T12:25:22.782541Z","iopub.status.idle":"2022-07-17T12:25:22.792028Z","shell.execute_reply.started":"2022-07-17T12:25:22.782489Z","shell.execute_reply":"2022-07-17T12:25:22.790685Z"},"trusted":true},"execution_count":null,"outputs":[]}]}