{"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\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 read-only \"../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# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-23T20:59:22.705865Z","iopub.execute_input":"2023-05-23T20:59:22.706516Z","iopub.status.idle":"2023-05-23T20:59:22.738656Z","shell.execute_reply.started":"2023-05-23T20:59:22.706477Z","shell.execute_reply":"2023-05-23T20:59:22.737793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load the train data\ntrain_df = pd.read_csv(\"/kaggle/input/titanic/train.csv\")\n# print head\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-23T20:59:50.682495Z","iopub.execute_input":"2023-05-23T20:59:50.682871Z","iopub.status.idle":"2023-05-23T20:59:50.738042Z","shell.execute_reply.started":"2023-05-23T20:59:50.682844Z","shell.execute_reply":"2023-05-23T20:59:50.737156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load the test data\ntest_df = pd.read_csv(\"/kaggle/input/titanic/test.csv\")\n# print head\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-23T21:07:00.185409Z","iopub.execute_input":"2023-05-23T21:07:00.186817Z","iopub.status.idle":"2023-05-23T21:07:00.204343Z","shell.execute_reply.started":"2023-05-23T21:07:00.186770Z","shell.execute_reply":"2023-05-23T21:07:00.203202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import classification_report\n\ny = train_df[\"Survived\"]\nfeatures = [\"Pclass\", \"Sex\", \"SibSp\", \"Parch\"]\n\nX = pd.get_dummies(train_df[features])\nX_test = pd.get_dummies(test_df[features])\n\nmodel = LogisticRegression()\nmodel.fit(X, y)\n\npredictions = model.predict(X_test)\noutput = pd.DataFrame({'PassengerId': test_df.PassengerId, 'Survived': predictions})\n\noutput.to_csv('submission.csv', index=False)\nprint(\"Submission was saved\")\n\n# Evaluation\ny_true = train_df[\"Survived\"]\ny_pred = model.predict(X)\nreport = classification_report(y_true, y_pred)\nprint(\"Classification Report:\\n\", report)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-23T21:12:52.166751Z","iopub.execute_input":"2023-05-23T21:12:52.167088Z","iopub.status.idle":"2023-05-23T21:12:52.197460Z","shell.execute_reply.started":"2023-05-23T21:12:52.167063Z","shell.execute_reply":"2023-05-23T21:12:52.196670Z"},"trusted":true},"execution_count":null,"outputs":[]}]}