{"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 ==========================================\nimport pandas as pd\nfrom sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2022-08-13T21:23:48.224673Z","iopub.execute_input":"2022-08-13T21:23:48.224952Z","iopub.status.idle":"2022-08-13T21:23:48.656581Z","shell.execute_reply.started":"2022-08-13T21:23:48.224929Z","shell.execute_reply":"2022-08-13T21:23:48.655419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2022-08-13T21:25:41.714213Z","iopub.execute_input":"2022-08-13T21:25:41.714489Z","iopub.status.idle":"2022-08-13T21:25:41.721794Z","shell.execute_reply.started":"2022-08-13T21:25:41.714466Z","shell.execute_reply":"2022-08-13T21:25:41.720861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =========================== VISUALISATION ===================================\ndata_train = pd.read_csv(\"/kaggle/input/titanic/train.csv\")\ndata_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T21:27:11.919127Z","iopub.execute_input":"2022-08-13T21:27:11.919525Z","iopub.status.idle":"2022-08-13T21:27:11.942130Z","shell.execute_reply.started":"2022-08-13T21:27:11.919502Z","shell.execute_reply":"2022-08-13T21:27:11.941553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =============================================================================\n# =========================== BUILD DATA train/test ===========================\n# =============================================================================\n\n# =============== data_train\ncolumn_input = [\"Sex\",\"Age\",\"Embarked\",\"Pclass\"]\ncolumn_class = [\"Survived\"]\ncolumn_keep = column_input+column_class\ndata_train = data_train.dropna(subset=column_keep)\n\ndata_train_Input = data_train[column_input]\ndata_train_Input = pd.get_dummies(data_train_Input)\ndata_train_Class = data_train[column_class]\n\n# =============== data_test\ndata_test = pd.read_csv(\"/kaggle/input/titanic/test.csv\")\ndata_test_Input = pd.get_dummies(data_test[column_input])\ndata_test_Input = data_test_Input.fillna(data_test_Input.mean())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T21:27:21.428378Z","iopub.execute_input":"2022-08-13T21:27:21.428681Z","iopub.status.idle":"2022-08-13T21:27:21.466669Z","shell.execute_reply.started":"2022-08-13T21:27:21.428659Z","shell.execute_reply":"2022-08-13T21:27:21.465509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =============================================================================\n# ================================= BUILD MODEL ===============================\n# =============================================================================\nmodel = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=1)\nmodel.fit(data_train_Input, data_train_Class)\npredictions = model.predict(data_test_Input)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T21:27:30.750757Z","iopub.execute_input":"2022-08-13T21:27:30.751030Z","iopub.status.idle":"2022-08-13T21:27:30.900096Z","shell.execute_reply.started":"2022-08-13T21:27:30.751007Z","shell.execute_reply":"2022-08-13T21:27:30.899146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = pd.DataFrame({'PassengerId': data_test.PassengerId, 'Survived': predictions})\noutput.to_csv('my_submission.csv', index=False)\nprint(\"Your submission was successfully saved!\")","metadata":{"execution":{"iopub.status.busy":"2022-08-13T21:27:46.966796Z","iopub.execute_input":"2022-08-13T21:27:46.967107Z","iopub.status.idle":"2022-08-13T21:27:46.976194Z","shell.execute_reply.started":"2022-08-13T21:27:46.967084Z","shell.execute_reply":"2022-08-13T21:27:46.975504Z"},"trusted":true},"execution_count":null,"outputs":[]}]}