{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":96164,"databundleVersionId":11418275,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import TimeSeriesSplit\nfrom sklearn.preprocessing import RobustScaler\nfrom sklearn.feature_selection import SelectKBest, mutual_info_regression\nfrom sklearn.metrics import mean_squared_error\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.utils.data import TensorDataset, DataLoader","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:00:04.467865Z","iopub.execute_input":"2025-07-07T18:00:04.470319Z","iopub.status.idle":"2025-07-07T18:00:04.477783Z","shell.execute_reply.started":"2025-07-07T18:00:04.470213Z","shell.execute_reply":"2025-07-07T18:00:04.476865Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Set random seeds for reproducibility\nnp.random.seed(42)\ntorch.manual_seed(42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:00:05.293353Z","iopub.execute_input":"2025-07-07T18:00:05.293711Z","iopub.status.idle":"2025-07-07T18:00:05.304259Z","shell.execute_reply.started":"2025-07-07T18:00:05.293685Z","shell.execute_reply":"2025-07-07T18:00:05.303279Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Loading Data","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_parquet(\"/kaggle/input/drw-crypto-market-prediction/train.parquet\")\ntest_df = pd.read_parquet(\"/kaggle/input/drw-crypto-market-prediction/test.parquet\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:00:06.556149Z","iopub.execute_input":"2025-07-07T18:00:06.557081Z","iopub.status.idle":"2025-07-07T18:01:01.330776Z","shell.execute_reply.started":"2025-07-07T18:00:06.557048Z","shell.execute_reply":"2025-07-07T18:01:01.329746Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### EDA","metadata":{}},{"cell_type":"code","source":"print(train_df.isna().sum().sum())\nprint(\"#\"*30)\nprint(test_df.isna().sum().sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:01:01.332247Z","iopub.execute_input":"2025-07-07T18:01:01.332602Z","iopub.status.idle":"2025-07-07T18:01:05.049831Z","shell.execute_reply.started":"2025-07-07T18:01:01.332575Z","shell.execute_reply":"2025-07-07T18:01:05.048891Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df[\"label\"].describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:01:05.050919Z","iopub.execute_input":"2025-07-07T18:01:05.051355Z","iopub.status.idle":"2025-07-07T18:01:05.127317Z","shell.execute_reply.started":"2025-07-07T18:01:05.051323Z","shell.execute_reply":"2025-07-07T18:01:05.126409Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Check For Problematic values","metadata":{}},{"cell_type":"code","source":"print(f\"Any Inf: ==> {np.isinf(train_df.to_numpy()).sum()} && {np.isinf(test_df.to_numpy()).sum()}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:03:01.070216Z","iopub.execute_input":"2025-07-07T18:03:01.070727Z","iopub.status.idle":"2025-07-07T18:03:06.075531Z","shell.execute_reply.started":"2025-07-07T18:03:01.070692Z","shell.execute_reply":"2025-07-07T18:03:06.073301Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"count_inf = pd.DataFrame({\n    \"train_inf\": np.isinf(train_df).sum(),\n    \"test_inf\": np.isinf(test_df).sum()\n})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:03:06.077312Z","iopub.execute_input":"2025-07-07T18:03:06.078190Z","iopub.status.idle":"2025-07-07T18:03:10.159720Z","shell.execute_reply.started":"2025-07-07T18:03:06.078153Z","shell.execute_reply":"2025-07-07T18:03:10.158669Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"count_inf = count_inf[(count_inf[\"train_inf\"] > 0) | (count_inf[\"test_inf\"] > 0)]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:03:12.569255Z","iopub.execute_input":"2025-07-07T18:03:12.569595Z","iopub.status.idle":"2025-07-07T18:03:12.585568Z","shell.execute_reply.started":"2025-07-07T18:03:12.569572Z","shell.execute_reply":"2025-07-07T18:03:12.584363Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Columns That contain Inf Values..... \")\nprint(f\"There are ==> {len(count_inf)} Columns Contain inf value\")\ncount_inf","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:03:13.117628Z","iopub.execute_input":"2025-07-07T18:03:13.118024Z","iopub.status.idle":"2025-07-07T18:03:13.134286Z","shell.execute_reply.started":"2025-07-07T18:03:13.117995Z","shell.execute_reply":"2025-07-07T18:03:13.133030Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Preprocessing","metadata":{}},{"cell_type":"code","source":"X = train_df.drop(columns=[\"label\"] + list(count_inf.index))\ny= train_df[\"label\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:03:15.514675Z","iopub.execute_input":"2025-07-07T18:03:15.515055Z","iopub.status.idle":"2025-07-07T18:03:18.258653Z","shell.execute_reply.started":"2025-07-07T18:03:15.515026Z","shell.execute_reply":"2025-07-07T18:03:18.257612Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_test = test_df.drop(columns=['label'] + list(count_inf.index))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:03:31.305530Z","iopub.execute_input":"2025-07-07T18:03:31.305948Z","iopub.status.idle":"2025-07-07T18:03:33.825302Z","shell.execute_reply.started":"2025-07-07T18:03:31.305913Z","shell.execute_reply":"2025-07-07T18:03:33.824096Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tscv = TimeSeriesSplit(n_splits=5)\nsplits = list(tscv.split(X))\ntrain_idx, val_idx = splits[-1] \nX_train, X_val = X.iloc[train_idx], X.iloc[val_idx]  # Add .iloc here\ny_train, y_val = y.iloc[train_idx], y.iloc[val_idx] ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:07:28.216357Z","iopub.execute_input":"2025-07-07T18:07:28.216773Z","iopub.status.idle":"2025-07-07T18:07:34.711348Z","shell.execute_reply.started":"2025-07-07T18:07:28.216742Z","shell.execute_reply":"2025-07-07T18:07:34.710461Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"scaler = RobustScaler()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:06:10.104696Z","iopub.execute_input":"2025-07-07T18:06:10.105083Z","iopub.status.idle":"2025-07-07T18:06:10.109559Z","shell.execute_reply.started":"2025-07-07T18:06:10.105057Z","shell.execute_reply":"2025-07-07T18:06:10.108560Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_scaled = scaler.fit_transform(X_train)\nX_val_scaled = scaler.transform(X_val)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:09:05.989041Z","iopub.execute_input":"2025-07-07T18:09:05.989475Z","iopub.status.idle":"2025-07-07T18:09:26.087090Z","shell.execute_reply.started":"2025-07-07T18:09:05.989448Z","shell.execute_reply":"2025-07-07T18:09:26.085721Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_scaled = pd.DataFrame(X_train_scaled, columns=X_train.columns)\nX_val_scaled = pd.DataFrame(X_val_scaled, columns=X_val.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:11:11.609187Z","iopub.execute_input":"2025-07-07T18:11:11.609820Z","iopub.status.idle":"2025-07-07T18:11:11.615551Z","shell.execute_reply.started":"2025-07-07T18:11:11.609780Z","shell.execute_reply":"2025-07-07T18:11:11.614467Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train_scaled.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:11:13.472636Z","iopub.execute_input":"2025-07-07T18:11:13.473116Z","iopub.status.idle":"2025-07-07T18:11:13.504598Z","shell.execute_reply.started":"2025-07-07T18:11:13.473084Z","shell.execute_reply":"2025-07-07T18:11:13.503849Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Select Best Features\n\nselector = SelectKBest(score_func=mutual_info_regression, k=100)\nX_train = selector.fit_transform(X_train_scaled, y_train)\nX_val = selector.transform(X_val_scaled)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-07T18:14:38.455775Z","iopub.execute_input":"2025-07-07T18:14:38.457076Z","execution_failed":"2025-07-07T18:14:50.401Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}