{"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":"!pip install pycaret --ignore-installed llvmlite","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-08-05T18:27:48.948777Z","iopub.execute_input":"2022-08-05T18:27:48.950678Z","iopub.status.idle":"2022-08-05T18:31:34.793926Z","shell.execute_reply.started":"2022-08-05T18:27:48.950511Z","shell.execute_reply":"2022-08-05T18:31:34.791978Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport pandas as pd\nfrom pycaret.classification import *","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:04.450282Z","iopub.execute_input":"2022-08-05T18:32:04.450802Z","iopub.status.idle":"2022-08-05T18:32:07.486346Z","shell.execute_reply.started":"2022-08-05T18:32:04.450755Z","shell.execute_reply":"2022-08-05T18:32:07.485094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train Data","metadata":{}},{"cell_type":"code","source":"Train = pd.read_csv(\"../input/titanic/train.csv\")\nTrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:31.404010Z","iopub.execute_input":"2022-08-05T18:32:31.405324Z","iopub.status.idle":"2022-08-05T18:32:31.452439Z","shell.execute_reply.started":"2022-08-05T18:32:31.405264Z","shell.execute_reply":"2022-08-05T18:32:31.451002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:34.205726Z","iopub.execute_input":"2022-08-05T18:32:34.206369Z","iopub.status.idle":"2022-08-05T18:32:34.249194Z","shell.execute_reply.started":"2022-08-05T18:32:34.206313Z","shell.execute_reply":"2022-08-05T18:32:34.247547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:36.620220Z","iopub.execute_input":"2022-08-05T18:32:36.621082Z","iopub.status.idle":"2022-08-05T18:32:36.632622Z","shell.execute_reply.started":"2022-08-05T18:32:36.621027Z","shell.execute_reply":"2022-08-05T18:32:36.631092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['Title'] = Train['Name'].str.split(\", \", expand=True)[1].str.split(\".\", expand=True)[0]\nTrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:39.711922Z","iopub.execute_input":"2022-08-05T18:32:39.712353Z","iopub.status.idle":"2022-08-05T18:32:39.739906Z","shell.execute_reply.started":"2022-08-05T18:32:39.712319Z","shell.execute_reply":"2022-08-05T18:32:39.738911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train[\"Age\"].fillna(Train.groupby(\"Title\")[\"Age\"].transform('mean'), inplace = True)\nTrain[\"Embarked\"].fillna(Train[\"Embarked\"].mode()[0], inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:42.628113Z","iopub.execute_input":"2022-08-05T18:32:42.629129Z","iopub.status.idle":"2022-08-05T18:32:42.640361Z","shell.execute_reply.started":"2022-08-05T18:32:42.629090Z","shell.execute_reply":"2022-08-05T18:32:42.639204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nTrain[\"Single\"] = np.where((Train[\"SibSp\"] + Train[\"Parch\"]) > 0, 0, 1)\nTrain['Cabin_control'] = np.where(Train[\"Cabin\"].isna(), 0, 1)\nTrain.drop([\"PassengerId\",\"Name\", \"SibSp\", \n         \"Parch\", \"Ticket\", \"Cabin\"], axis = 1, inplace = True)\n\nTrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:45.516820Z","iopub.execute_input":"2022-08-05T18:32:45.517339Z","iopub.status.idle":"2022-08-05T18:32:45.547097Z","shell.execute_reply.started":"2022-08-05T18:32:45.517291Z","shell.execute_reply":"2022-08-05T18:32:45.545655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:32:50.479363Z","iopub.execute_input":"2022-08-05T18:32:50.479841Z","iopub.status.idle":"2022-08-05T18:32:50.490519Z","shell.execute_reply.started":"2022-08-05T18:32:50.479805Z","shell.execute_reply":"2022-08-05T18:32:50.489190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#  Pycaret Model","metadata":{}},{"cell_type":"code","source":"model = setup(data = Train, target = 'Survived')","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:36:09.311951Z","iopub.execute_input":"2022-08-05T18:36:09.312958Z","iopub.status.idle":"2022-08-05T18:36:13.344735Z","shell.execute_reply.started":"2022-08-05T18:36:09.312911Z","shell.execute_reply":"2022-08-05T18:36:13.343572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"models = compare_models()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:36:17.124480Z","iopub.execute_input":"2022-08-05T18:36:17.124950Z","iopub.status.idle":"2022-08-05T18:36:55.817750Z","shell.execute_reply.started":"2022-08-05T18:36:17.124913Z","shell.execute_reply":"2022-08-05T18:36:55.816608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_model = tune_model(models)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:38:08.779400Z","iopub.execute_input":"2022-08-05T18:38:08.779966Z","iopub.status.idle":"2022-08-05T18:38:33.031930Z","shell.execute_reply.started":"2022-08-05T18:38:08.779924Z","shell.execute_reply":"2022-08-05T18:38:33.030479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test Data","metadata":{}},{"cell_type":"code","source":"Test = pd.read_csv(\"../input/titanic/test.csv\")\nTest.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:39:23.867981Z","iopub.execute_input":"2022-08-05T18:39:23.869053Z","iopub.status.idle":"2022-08-05T18:39:23.899367Z","shell.execute_reply.started":"2022-08-05T18:39:23.868988Z","shell.execute_reply":"2022-08-05T18:39:23.897851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:39:26.589405Z","iopub.execute_input":"2022-08-05T18:39:26.589816Z","iopub.status.idle":"2022-08-05T18:39:26.607986Z","shell.execute_reply.started":"2022-08-05T18:39:26.589780Z","shell.execute_reply":"2022-08-05T18:39:26.606426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test['Title'] = Test['Name'].str.split(\", \", expand=True)[1].str.split(\".\", expand=True)[0]\nTest.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:41:07.377838Z","iopub.execute_input":"2022-08-05T18:41:07.378459Z","iopub.status.idle":"2022-08-05T18:41:07.407119Z","shell.execute_reply.started":"2022-08-05T18:41:07.378413Z","shell.execute_reply":"2022-08-05T18:41:07.405286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test[\"Age\"].fillna(Test.groupby(\"Title\")[\"Age\"].transform('mean'), inplace = True)\nTest[\"Embarked\"].fillna(Train[\"Embarked\"].mode()[0], inplace = True)\nTest[\"Fare\"].fillna(Test['Fare'].mean(), inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:41:11.029494Z","iopub.execute_input":"2022-08-05T18:41:11.030703Z","iopub.status.idle":"2022-08-05T18:41:11.042522Z","shell.execute_reply.started":"2022-08-05T18:41:11.030659Z","shell.execute_reply":"2022-08-05T18:41:11.041246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test[\"Single\"] = np.where((Test[\"SibSp\"] + Test[\"Parch\"]) > 0, 0, 1)\nTest['Cabin_control'] = np.where(Test[\"Cabin\"].isna(), 0, 1)\nTest.drop([\"PassengerId\",\"Name\", \"SibSp\", \n         \"Parch\", \"Ticket\", \"Cabin\"], axis = 1, inplace = True)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:41:13.855154Z","iopub.execute_input":"2022-08-05T18:41:13.855922Z","iopub.status.idle":"2022-08-05T18:41:13.868750Z","shell.execute_reply.started":"2022-08-05T18:41:13.855882Z","shell.execute_reply":"2022-08-05T18:41:13.867638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:41:16.100049Z","iopub.execute_input":"2022-08-05T18:41:16.101099Z","iopub.status.idle":"2022-08-05T18:41:16.124911Z","shell.execute_reply.started":"2022-08-05T18:41:16.101037Z","shell.execute_reply":"2022-08-05T18:41:16.123516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predict","metadata":{}},{"cell_type":"code","source":"predict = predict_model(best_model, Test)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:41:56.105424Z","iopub.execute_input":"2022-08-05T18:41:56.105825Z","iopub.status.idle":"2022-08-05T18:41:56.406194Z","shell.execute_reply.started":"2022-08-05T18:41:56.105793Z","shell.execute_reply":"2022-08-05T18:41:56.404832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final = pd.read_csv(\"../input/titanic/gender_submission.csv\")\nfinal.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:41:59.425062Z","iopub.execute_input":"2022-08-05T18:41:59.425635Z","iopub.status.idle":"2022-08-05T18:41:59.446391Z","shell.execute_reply.started":"2022-08-05T18:41:59.425586Z","shell.execute_reply":"2022-08-05T18:41:59.445273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:42:02.034093Z","iopub.execute_input":"2022-08-05T18:42:02.034765Z","iopub.status.idle":"2022-08-05T18:42:02.055081Z","shell.execute_reply.started":"2022-08-05T18:42:02.034711Z","shell.execute_reply":"2022-08-05T18:42:02.053627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final[\"Survived\"] = predict[\"Label\"]\nfinal.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:42:04.918301Z","iopub.execute_input":"2022-08-05T18:42:04.918755Z","iopub.status.idle":"2022-08-05T18:42:04.933222Z","shell.execute_reply.started":"2022-08-05T18:42:04.918694Z","shell.execute_reply":"2022-08-05T18:42:04.931930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final['Survived'] = final['Survived'].astype('int')","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:42:23.750996Z","iopub.execute_input":"2022-08-05T18:42:23.751630Z","iopub.status.idle":"2022-08-05T18:42:23.760596Z","shell.execute_reply.started":"2022-08-05T18:42:23.751575Z","shell.execute_reply":"2022-08-05T18:42:23.759117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final.to_csv(\"final.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-05T18:42:25.891625Z","iopub.execute_input":"2022-08-05T18:42:25.892194Z","iopub.status.idle":"2022-08-05T18:42:25.901627Z","shell.execute_reply.started":"2022-08-05T18:42:25.892124Z","shell.execute_reply":"2022-08-05T18:42:25.900576Z"},"trusted":true},"execution_count":null,"outputs":[]}]}