{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":96164,"databundleVersionId":11418275,"sourceType":"competition"}],"dockerImageVersionId":31041,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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-07-04T13:43:53.586125Z","iopub.execute_input":"2025-07-04T13:43:53.586356Z","iopub.status.idle":"2025-07-04T13:43:54.030045Z","shell.execute_reply.started":"2025-07-04T13:43:53.586336Z","shell.execute_reply":"2025-07-04T13:43:54.029109Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport xgboost as xgb","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:36:19.304876Z","iopub.execute_input":"2025-07-05T04:36:19.305135Z","iopub.status.idle":"2025-07-05T04:36:22.769540Z","shell.execute_reply.started":"2025-07-05T04:36:19.305117Z","shell.execute_reply":"2025-07-05T04:36:22.768767Z"}},"outputs":[],"execution_count":null},{"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-05T04:36:28.392109Z","iopub.execute_input":"2025-07-05T04:36:28.392639Z","iopub.status.idle":"2025-07-05T04:37:10.177016Z","shell.execute_reply.started":"2025-07-05T04:36:28.392618Z","shell.execute_reply":"2025-07-05T04:37:10.176205Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.head(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T02:26:41.813750Z","iopub.execute_input":"2025-07-05T02:26:41.814032Z","iopub.status.idle":"2025-07-05T02:26:41.846589Z","shell.execute_reply.started":"2025-07-05T02:26:41.814011Z","shell.execute_reply":"2025-07-05T02:26:41.846005Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T02:26:45.028053Z","iopub.execute_input":"2025-07-05T02:26:45.028591Z","iopub.status.idle":"2025-07-05T02:26:45.050117Z","shell.execute_reply.started":"2025-07-05T02:26:45.028568Z","shell.execute_reply":"2025-07-05T02:26:45.049505Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T14:08:18.635431Z","iopub.execute_input":"2025-07-04T14:08:18.636318Z","iopub.status.idle":"2025-07-04T14:08:18.677901Z","shell.execute_reply.started":"2025-07-04T14:08:18.636287Z","shell.execute_reply":"2025-07-04T14:08:18.677058Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\n\nfor col in train_df.columns:\n    col_type = train_df[col].dtype\n\n    if col_type == 'int64':\n        # Check min/max to choose int32 or int16\n        if train_df[col].min() > np.iinfo(np.int16).min and train_df[col].max() < np.iinfo(np.int16).max:\n            train_df[col] = train_df[col].astype(np.int16)\n        else:\n            train_df[col] = train_df[col].astype(np.int32)\n\n    elif col_type == 'float64':\n        train_df[col] = train_df[col].astype(np.float32)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:37:14.830483Z","iopub.execute_input":"2025-07-05T04:37:14.831163Z","iopub.status.idle":"2025-07-05T04:37:17.290364Z","shell.execute_reply.started":"2025-07-05T04:37:14.831138Z","shell.execute_reply":"2025-07-05T04:37:17.289715Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T02:29:44.958693Z","iopub.execute_input":"2025-07-05T02:29:44.959158Z","iopub.status.idle":"2025-07-05T02:29:45.005350Z","shell.execute_reply.started":"2025-07-05T02:29:44.959133Z","shell.execute_reply":"2025-07-05T02:29:45.004737Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\n\nfor col in test_df.columns:\n    col_type = test_df[col].dtype\n\n    if col_type == 'int64':\n        # Check min/max to choose int32 or int16\n        if test_df[col].min() > np.iinfo(np.int16).min and test_df[col].max() < np.iinfo(np.int16).max:\n            test_df[col] = test_df[col].astype(np.int16)\n        else:\n            test_df[col] = test_df[col].astype(np.int32)\n\n    elif col_type == 'float64':\n        test_df[col] = test_df[col].astype(np.float32)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:37:22.132076Z","iopub.execute_input":"2025-07-05T04:37:22.132342Z","iopub.status.idle":"2025-07-05T04:37:24.569127Z","shell.execute_reply.started":"2025-07-05T04:37:22.132322Z","shell.execute_reply":"2025-07-05T04:37:24.568103Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T03:49:35.763085Z","iopub.execute_input":"2025-07-05T03:49:35.763780Z","iopub.status.idle":"2025-07-05T03:49:35.768211Z","shell.execute_reply.started":"2025-07-05T03:49:35.763755Z","shell.execute_reply":"2025-07-05T03:49:35.767536Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isna().sum()[train_df.isna().sum() > 0]\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T14:08:21.885315Z","iopub.execute_input":"2025-07-04T14:08:21.885656Z","iopub.status.idle":"2025-07-04T14:08:25.906929Z","shell.execute_reply.started":"2025-07-04T14:08:21.885631Z","shell.execute_reply":"2025-07-04T14:08:25.905968Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.isna().sum()[test_df.isna().sum() > 0]\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T14:08:29.626323Z","iopub.execute_input":"2025-07-04T14:08:29.626760Z","iopub.status.idle":"2025-07-04T14:08:33.231191Z","shell.execute_reply.started":"2025-07-04T14:08:29.626728Z","shell.execute_reply":"2025-07-04T14:08:33.230313Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.select_dtypes(include='object').columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T14:08:39.445138Z","iopub.execute_input":"2025-07-04T14:08:39.445411Z","iopub.status.idle":"2025-07-04T14:08:39.451878Z","shell.execute_reply.started":"2025-07-04T14:08:39.445394Z","shell.execute_reply":"2025-07-04T14:08:39.450683Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = train_df.reset_index(drop=True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:37:30.112404Z","iopub.execute_input":"2025-07-05T04:37:30.112700Z","iopub.status.idle":"2025-07-05T04:37:32.872119Z","shell.execute_reply.started":"2025-07-05T04:37:30.112680Z","shell.execute_reply":"2025-07-05T04:37:32.871539Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T14:14:42.958777Z","iopub.execute_input":"2025-07-04T14:14:42.959088Z","iopub.status.idle":"2025-07-04T14:14:42.987174Z","shell.execute_reply.started":"2025-07-04T14:14:42.959070Z","shell.execute_reply":"2025-07-04T14:14:42.986633Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df = test_df.reset_index()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:37:35.062486Z","iopub.execute_input":"2025-07-05T04:37:35.063165Z","iopub.status.idle":"2025-07-05T04:37:37.985656Z","shell.execute_reply.started":"2025-07-05T04:37:35.063127Z","shell.execute_reply":"2025-07-05T04:37:37.985122Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ids = test_df['ID'].copy()\ntest_df.drop(columns = ['ID'],inplace = True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:37:43.112155Z","iopub.execute_input":"2025-07-05T04:37:43.112781Z","iopub.status.idle":"2025-07-05T04:37:43.673907Z","shell.execute_reply.started":"2025-07-05T04:37:43.112756Z","shell.execute_reply":"2025-07-05T04:37:43.673293Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX = train_df.drop(columns = ['label'])\ny = train_df['label']\n\n\nx_train,x_test,y_train,y_test = train_test_split(X,y,test_size = 0.2, random_state = 42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:37:46.202189Z","iopub.execute_input":"2025-07-05T04:37:46.202854Z","iopub.status.idle":"2025-07-05T04:37:49.037589Z","shell.execute_reply.started":"2025-07-05T04:37:46.202828Z","shell.execute_reply":"2025-07-05T04:37:49.037033Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\n\n# Check for infinite values\nprint(np.isinf(X).sum())  # count of infinite values in training features\n\n# Check for very large values (e.g., >1e10)\nprint((X > 1e10).sum())\nprint((X < -1e10).sum())\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:41:03.834005Z","iopub.execute_input":"2025-07-05T04:41:03.834834Z","iopub.status.idle":"2025-07-05T04:41:07.108001Z","shell.execute_reply.started":"2025-07-05T04:41:03.834801Z","shell.execute_reply":"2025-07-05T04:41:07.107140Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X.replace([np.inf, -np.inf], np.nan, inplace=True)\n# x_test.replace([np.inf, -np.inf], np.nan, inplace=True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:41:47.022896Z","iopub.execute_input":"2025-07-05T04:41:47.023155Z","iopub.status.idle":"2025-07-05T04:41:50.027628Z","shell.execute_reply.started":"2025-07-05T04:41:47.023135Z","shell.execute_reply":"2025-07-05T04:41:50.026867Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.replace([np.inf, -np.inf], np.nan, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:38:01.272976Z","iopub.execute_input":"2025-07-05T04:38:01.273250Z","iopub.status.idle":"2025-07-05T04:38:04.326457Z","shell.execute_reply.started":"2025-07-05T04:38:01.273229Z","shell.execute_reply":"2025-07-05T04:38:04.325918Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# x_train.fillna(method='ffill', inplace=True)  # forward fill\n# x_test.fillna(method='ffill', inplace=True)\ntest_df.fillna(method='ffill', inplace=True)\nX.fillna(method='ffill', inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:42:12.822484Z","iopub.execute_input":"2025-07-05T04:42:12.823325Z","iopub.status.idle":"2025-07-05T04:42:15.803340Z","shell.execute_reply.started":"2025-07-05T04:42:12.823299Z","shell.execute_reply":"2025-07-05T04:42:15.802785Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"assert not np.isinf(X).any().any(), \"Still have inf in X_train\"\n# assert not np.isinf(x_test).any().any(), \"Still have inf in X_val\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:42:24.683085Z","iopub.execute_input":"2025-07-05T04:42:24.683341Z","iopub.status.idle":"2025-07-05T04:42:25.949342Z","shell.execute_reply.started":"2025-07-05T04:42:24.683322Z","shell.execute_reply":"2025-07-05T04:42:25.948754Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:38:15.041709Z","iopub.execute_input":"2025-07-05T04:38:15.042012Z","iopub.status.idle":"2025-07-05T04:38:15.047406Z","shell.execute_reply.started":"2025-07-05T04:38:15.041993Z","shell.execute_reply":"2025-07-05T04:38:15.046657Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from xgboost import XGBRegressor\n\nxgb_model = XGBRegressor(\n    n_estimators=3000,\n    learning_rate=0.05,\n    # max_depth=6,\n    tree_method='gpu_hist',\n    # subsample=0.8,\n    # colsample_bytree=0.8\n)\n\nxgb_model.fit(X,y)\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:50:25.833364Z","iopub.execute_input":"2025-07-05T04:50:25.833622Z","iopub.status.idle":"2025-07-05T04:59:34.643386Z","shell.execute_reply.started":"2025-07-05T04:50:25.833604Z","shell.execute_reply":"2025-07-05T04:59:34.642790Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.drop(columns = ['label'],inplace = True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:59:42.514027Z","iopub.execute_input":"2025-07-05T04:59:42.514692Z","iopub.status.idle":"2025-07-05T04:59:42.529792Z","shell.execute_reply.started":"2025-07-05T04:59:42.514670Z","shell.execute_reply":"2025-07-05T04:59:42.528704Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"batch_size = 10000\npredictions = []\n\nfor i in range(0, len(test_df), batch_size):\n    batch_pred = xgb_model.predict(test_df.iloc[i:i+batch_size])\n    predictions.extend(batch_pred)\n\npredictions = np.array(predictions)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T04:59:52.102596Z","iopub.execute_input":"2025-07-05T04:59:52.103009Z","iopub.status.idle":"2025-07-05T05:00:38.593125Z","shell.execute_reply.started":"2025-07-05T04:59:52.102962Z","shell.execute_reply":"2025-07-05T05:00:38.592518Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T05:00:55.461420Z","iopub.execute_input":"2025-07-05T05:00:55.462166Z","iopub.status.idle":"2025-07-05T05:00:55.467197Z","shell.execute_reply.started":"2025-07-05T05:00:55.462132Z","shell.execute_reply":"2025-07-05T05:00:55.466632Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n    'ID' : ids,\n    'prediction': predictions\n})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T05:00:59.301546Z","iopub.execute_input":"2025-07-05T05:00:59.301830Z","iopub.status.idle":"2025-07-05T05:00:59.306577Z","shell.execute_reply.started":"2025-07-05T05:00:59.301810Z","shell.execute_reply":"2025-07-05T05:00:59.306065Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T05:01:03.311377Z","iopub.execute_input":"2025-07-05T05:01:03.311608Z","iopub.status.idle":"2025-07-05T05:01:03.330174Z","shell.execute_reply.started":"2025-07-05T05:01:03.311592Z","shell.execute_reply":"2025-07-05T05:01:03.329433Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv('submission2.csv', index=False)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-05T05:01:12.493247Z","iopub.execute_input":"2025-07-05T05:01:12.493506Z","iopub.status.idle":"2025-07-05T05:01:13.239517Z","shell.execute_reply.started":"2025-07-05T05:01:12.493486Z","shell.execute_reply":"2025-07-05T05:01:13.238783Z"}},"outputs":[],"execution_count":null}]}