{"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 in \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 \"../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# Any results you write to the current directory are saved as output.","metadata":{"_kg_hide-input":false,"execution":{"iopub.status.busy":"2022-07-22T16:02:04.877954Z","iopub.execute_input":"2022-07-22T16:02:04.878549Z","iopub.status.idle":"2022-07-22T16:02:05.102301Z","shell.execute_reply.started":"2022-07-22T16:02:04.878217Z","shell.execute_reply":"2022-07-22T16:02:05.101444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/titanic/train.csv\")\ntrain_data","metadata":{"execution":{"iopub.status.busy":"2022-07-22T16:02:05.103993Z","iopub.execute_input":"2022-07-22T16:02:05.104256Z","iopub.status.idle":"2022-07-22T16:02:05.153793Z","shell.execute_reply.started":"2022-07-22T16:02:05.104206Z","shell.execute_reply":"2022-07-22T16:02:05.152919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.read_csv(\"/kaggle/input/titanic/test.csv\")\ntest_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-22T16:02:05.154973Z","iopub.execute_input":"2022-07-22T16:02:05.155260Z","iopub.status.idle":"2022-07-22T16:02:05.179588Z","shell.execute_reply.started":"2022-07-22T16:02:05.155154Z","shell.execute_reply":"2022-07-22T16:02:05.178733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"women = train_data.loc[train_data.Sex == 'female'][\"Survived\"]\nrate_women = sum(women)/len(women)\n\nprint(\"% of women who survived:\", rate_women)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-22T16:02:05.180782Z","iopub.execute_input":"2022-07-22T16:02:05.181000Z","iopub.status.idle":"2022-07-22T16:02:05.191823Z","shell.execute_reply.started":"2022-07-22T16:02:05.180962Z","shell.execute_reply":"2022-07-22T16:02:05.190693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"men = train_data.loc[train_data.Sex == 'male'][\"Survived\"]\nrate_men = sum(men)/len(men)\n\nprint(\"% of men who survived:\", rate_men)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T16:02:05.194024Z","iopub.execute_input":"2022-07-22T16:02:05.194617Z","iopub.status.idle":"2022-07-22T16:02:05.202571Z","shell.execute_reply.started":"2022-07-22T16:02:05.194313Z","shell.execute_reply":"2022-07-22T16:02:05.201747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nfrom sklearn.impute import SimpleImputer\n\n#train_data = train_data.fillna(method=\"ffill\")\n\ny = train_data[\"Survived\"]\nfeatures = [\"Sex\", \"Pclass\", \"Fare\", \"Embarked\"]\nX = pd.get_dummies(train_data[features])\nmy_imputer = SimpleImputer()\nX = my_imputer.fit_transform(X)\nX_test = pd.get_dummies(test_data[features])\nX_test = my_imputer.transform(X_test)\n\nmodel = RandomForestClassifier(n_estimators=100000, max_depth=70, random_state= 30)\nmodel.fit(X, y)\npredictions = model.predict(X_test)\n\noutput = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})\noutput.to_csv('submission.csv', index=False)","metadata":{"_kg_hide-output":false,"execution":{"iopub.status.busy":"2022-07-22T16:26:31.840437Z","iopub.execute_input":"2022-07-22T16:26:31.840919Z","iopub.status.idle":"2022-07-22T16:28:30.340837Z","shell.execute_reply.started":"2022-07-22T16:26:31.840695Z","shell.execute_reply":"2022-07-22T16:28:30.339991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}