{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":114135,"databundleVersionId":14604229,"sourceType":"competition"}],"dockerImageVersionId":31192,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:24:57.687685Z","iopub.execute_input":"2025-12-16T20:24:57.687991Z","iopub.status.idle":"2025-12-16T20:25:00.235187Z","shell.execute_reply.started":"2025-12-16T20:24:57.687963Z","shell.execute_reply":"2025-12-16T20:25:00.234281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\nfrom scipy import stats\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:42:37.879218Z","iopub.execute_input":"2025-12-16T20:42:37.879665Z","iopub.status.idle":"2025-12-16T20:42:38.881916Z","shell.execute_reply.started":"2025-12-16T20:42:37.879635Z","shell.execute_reply":"2025-12-16T20:42:38.880893Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_file = \"/kaggle/input/detecting-reversal-points-in-us-equities/competition_data/competition_data/train.csv\"\ntest_file = \"/kaggle/input/detecting-reversal-points-in-us-equities/competition_data/competition_data/test.csv\"\nsubmission_file = \"/kaggle/input/detecting-reversal-points-in-us-equities/competition_data/competition_data/sample_submission.csv\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:28:58.356736Z","iopub.execute_input":"2025-12-16T20:28:58.357089Z","iopub.status.idle":"2025-12-16T20:28:58.361985Z","shell.execute_reply.started":"2025-12-16T20:28:58.357061Z","shell.execute_reply":"2025-12-16T20:28:58.361167Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv(train_file, low_memory=False)\ntest = pd.read_csv(test_file, low_memory=False)\nsubmission = pd.read_csv(submission_file, low_memory=False)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:29:03.364012Z","iopub.execute_input":"2025-12-16T20:29:03.364374Z","iopub.status.idle":"2025-12-16T20:29:34.635946Z","shell.execute_reply.started":"2025-12-16T20:29:03.364345Z","shell.execute_reply":"2025-12-16T20:29:34.634844Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:31:56.763064Z","iopub.execute_input":"2025-12-16T20:31:56.763395Z","iopub.status.idle":"2025-12-16T20:31:56.786779Z","shell.execute_reply.started":"2025-12-16T20:31:56.763370Z","shell.execute_reply":"2025-12-16T20:31:56.785615Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:31:45.914646Z","iopub.execute_input":"2025-12-16T20:31:45.914979Z","iopub.status.idle":"2025-12-16T20:31:45.946171Z","shell.execute_reply.started":"2025-12-16T20:31:45.914956Z","shell.execute_reply":"2025-12-16T20:31:45.945442Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:32:09.463715Z","iopub.execute_input":"2025-12-16T20:32:09.464019Z","iopub.status.idle":"2025-12-16T20:32:09.477178Z","shell.execute_reply.started":"2025-12-16T20:32:09.463996Z","shell.execute_reply":"2025-12-16T20:32:09.476022Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Missing value check\nprint(\"\\nMissing values:\")\nprint(\"Total mission values:\", train.isna().sum().sum())\nprint(train.isna().sum().sort_values(ascending=False))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:34:37.899286Z","iopub.execute_input":"2025-12-16T20:34:37.900267Z","iopub.status.idle":"2025-12-16T20:34:38.318975Z","shell.execute_reply.started":"2025-12-16T20:34:37.900211Z","shell.execute_reply":"2025-12-16T20:34:38.318106Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(test.isna().sum().sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:34:06.520952Z","iopub.execute_input":"2025-12-16T20:34:06.521295Z","iopub.status.idle":"2025-12-16T20:34:06.633946Z","shell.execute_reply.started":"2025-12-16T20:34:06.521229Z","shell.execute_reply":"2025-12-16T20:34:06.632898Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"\\nSummary stats:\")\nprint(train.describe())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:34:50.998375Z","iopub.execute_input":"2025-12-16T20:34:50.998773Z","iopub.status.idle":"2025-12-16T20:34:51.032012Z","shell.execute_reply.started":"2025-12-16T20:34:50.998745Z","shell.execute_reply":"2025-12-16T20:34:51.029561Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.columns.tolist()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:47:10.964804Z","iopub.execute_input":"2025-12-16T20:47:10.965159Z","iopub.status.idle":"2025-12-16T20:47:10.995720Z","shell.execute_reply.started":"2025-12-16T20:47:10.965136Z","shell.execute_reply":"2025-12-16T20:47:10.994612Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:38:53.464830Z","iopub.execute_input":"2025-12-16T20:38:53.465189Z","iopub.status.idle":"2025-12-16T20:38:56.015414Z","shell.execute_reply.started":"2025-12-16T20:38:53.465150Z","shell.execute_reply":"2025-12-16T20:38:56.014394Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.select_dtypes(include=['object'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:40:49.186931Z","iopub.execute_input":"2025-12-16T20:40:49.187230Z","iopub.status.idle":"2025-12-16T20:40:49.198614Z","shell.execute_reply.started":"2025-12-16T20:40:49.187209Z","shell.execute_reply":"2025-12-16T20:40:49.197506Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.select_dtypes(include=['int64', 'float64'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:41:12.467278Z","iopub.execute_input":"2025-12-16T20:41:12.467582Z","iopub.status.idle":"2025-12-16T20:41:12.481500Z","shell.execute_reply.started":"2025-12-16T20:41:12.467549Z","shell.execute_reply":"2025-12-16T20:41:12.480566Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.hist(bins=20, figsize=(10,8))\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:42:42.920833Z","iopub.execute_input":"2025-12-16T20:42:42.922280Z","iopub.status.idle":"2025-12-16T20:42:43.891877Z","shell.execute_reply.started":"2025-12-16T20:42:42.922215Z","shell.execute_reply":"2025-12-16T20:42:43.890999Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:49:14.768286Z","iopub.execute_input":"2025-12-16T20:49:14.768648Z","iopub.status.idle":"2025-12-16T20:49:14.882139Z","shell.execute_reply.started":"2025-12-16T20:49:14.768621Z","shell.execute_reply":"2025-12-16T20:49:14.881275Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# mapping\n\nmapping = {\n    'HH': 'H',\n    'LH': 'H',\n    'HL': 'L',\n    'LL': 'L',\n    np.nan: 'N'\n}\n\n\n# Drop metadata columns\nmeta_cols = ['id', 'train_id', 'Unnamed: 0', 'ticker_id', 't', 'class_label']\nfeatures = [col for col in train.columns if col not in meta_cols]\n\n# Apply mapping to target\ny = train['class_label'].map(mapping)\ny = y.fillna('N')  # In case there are NaN after mapping\n\nprint(\"Class distribution after mapping:\\n\", y.value_counts())\n\n# Encode target\nle = LabelEncoder()\ny_encoded = le.fit_transform(y)\n\n# Prepare features\nX = train[features].copy()\n\nprint(\"\\nEncoded class labels:\")\nfor orig, enc in zip(le.classes_, range(len(le.classes_))):\n    print(f\"{orig} -> {enc}\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:49:16.615463Z","iopub.execute_input":"2025-12-16T20:49:16.615892Z","iopub.status.idle":"2025-12-16T20:49:16.792409Z","shell.execute_reply.started":"2025-12-16T20:49:16.615858Z","shell.execute_reply":"2025-12-16T20:49:16.791402Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:48:13.996947Z","iopub.execute_input":"2025-12-16T20:48:13.997237Z","iopub.status.idle":"2025-12-16T20:48:14.005169Z","shell.execute_reply.started":"2025-12-16T20:48:13.997217Z","shell.execute_reply":"2025-12-16T20:48:14.004194Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:50:51.957030Z","iopub.execute_input":"2025-12-16T20:50:51.957386Z","iopub.status.idle":"2025-12-16T20:50:51.993532Z","shell.execute_reply.started":"2025-12-16T20:50:51.957351Z","shell.execute_reply":"2025-12-16T20:50:51.992587Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X.isna().sum().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-16T20:52:35.108076Z","iopub.execute_input":"2025-12-16T20:52:35.108426Z","iopub.status.idle":"2025-12-16T20:52:35.318667Z","shell.execute_reply.started":"2025-12-16T20:52:35.108400Z","shell.execute_reply":"2025-12-16T20:52:35.317817Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}