{"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":"gpu","dataSources":[{"sourceId":96164,"databundleVersionId":12993472,"sourceType":"competition"}],"dockerImageVersionId":31089,"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\n\n# !pip install -Uqq fastai\n!pip install -Uqq pyarrow\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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-09-12T14:59:10.617375Z","iopub.execute_input":"2025-09-12T14:59:10.617573Z","iopub.status.idle":"2025-09-12T14:59:18.497909Z","shell.execute_reply.started":"2025-09-12T14:59:10.617557Z","shell.execute_reply":"2025-09-12T14:59:18.497265Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\nbase_path = Path(\"/kaggle/input/drw-crypto-market-prediction/\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T14:59:50.075455Z","iopub.execute_input":"2025-09-12T14:59:50.076115Z","iopub.status.idle":"2025-09-12T14:59:50.080725Z","shell.execute_reply.started":"2025-09-12T14:59:50.076068Z","shell.execute_reply":"2025-09-12T14:59:50.079873Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pyarrow.parquet as pq","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T14:59:54.229621Z","iopub.execute_input":"2025-09-12T14:59:54.230270Z","iopub.status.idle":"2025-09-12T14:59:54.246835Z","shell.execute_reply.started":"2025-09-12T14:59:54.230237Z","shell.execute_reply":"2025-09-12T14:59:54.246220Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_table  = pq.read_pandas(base_path/'train.parquet')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T14:59:56.585848Z","iopub.execute_input":"2025-09-12T14:59:56.586478Z","iopub.status.idle":"2025-09-12T15:00:04.203401Z","shell.execute_reply.started":"2025-09-12T14:59:56.586447Z","shell.execute_reply":"2025-09-12T15:00:04.202361Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = train_table.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:00:04.204927Z","iopub.execute_input":"2025-09-12T15:00:04.205643Z","iopub.status.idle":"2025-09-12T15:00:05.734793Z","shell.execute_reply.started":"2025-09-12T15:00:04.205596Z","shell.execute_reply":"2025-09-12T15:00:05.734316Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:00:05.735434Z","iopub.execute_input":"2025-09-12T15:00:05.735636Z","iopub.status.idle":"2025-09-12T15:00:05.769500Z","shell.execute_reply.started":"2025-09-12T15:00:05.735619Z","shell.execute_reply":"2025-09-12T15:00:05.768791Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from fastai.tabular.all import *","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:00:05.770962Z","iopub.execute_input":"2025-09-12T15:00:05.771185Z","iopub.status.idle":"2025-09-12T15:00:10.982451Z","shell.execute_reply.started":"2025-09-12T15:00:05.771168Z","shell.execute_reply":"2025-09-12T15:00:10.981687Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"clist = list(train_df.columns.values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:00:10.983196Z","iopub.execute_input":"2025-09-12T15:00:10.983526Z","iopub.status.idle":"2025-09-12T15:00:10.987221Z","shell.execute_reply.started":"2025-09-12T15:00:10.983507Z","shell.execute_reply":"2025-09-12T15:00:10.986531Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_cols = clist.copy()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:00:10.988309Z","iopub.execute_input":"2025-09-12T15:00:10.988511Z","iopub.status.idle":"2025-09-12T15:00:11.005793Z","shell.execute_reply.started":"2025-09-12T15:00:10.988496Z","shell.execute_reply":"2025-09-12T15:00:11.005086Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_cols.remove(\"label\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:00:15.220336Z","iopub.execute_input":"2025-09-12T15:00:15.220606Z","iopub.status.idle":"2025-09-12T15:00:15.224364Z","shell.execute_reply.started":"2025-09-12T15:00:15.220586Z","shell.execute_reply":"2025-09-12T15:00:15.223615Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"splits = EndSplitter(valid_pct=0.1)(range_of(train_df))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:00:16.796328Z","iopub.execute_input":"2025-09-12T15:00:16.797172Z","iopub.status.idle":"2025-09-12T15:00:16.851823Z","shell.execute_reply.started":"2025-09-12T15:00:16.797141Z","shell.execute_reply":"2025-09-12T15:00:16.851037Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_to = TabularPandas(train_df,\n                   # procs=[Normalize],\n                   cont_names = train_cols,\n                   y_names='label',\n                   splits=splits)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:01:08.213243Z","iopub.execute_input":"2025-09-12T15:01:08.213518Z","iopub.status.idle":"2025-09-12T15:01:14.464660Z","shell.execute_reply.started":"2025-09-12T15:01:08.213497Z","shell.execute_reply":"2025-09-12T15:01:14.463878Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_to.xs.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:01:14.465864Z","iopub.execute_input":"2025-09-12T15:01:14.466151Z","iopub.status.idle":"2025-09-12T15:01:15.351246Z","shell.execute_reply.started":"2025-09-12T15:01:14.466128Z","shell.execute_reply":"2025-09-12T15:01:15.350469Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dls = train_to.dataloaders(bs=64)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:01:15.352090Z","iopub.execute_input":"2025-09-12T15:01:15.352833Z","iopub.status.idle":"2025-09-12T15:01:18.223386Z","shell.execute_reply.started":"2025-09-12T15:01:15.352807Z","shell.execute_reply":"2025-09-12T15:01:18.222586Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from fastai.metrics import AccumMetric\nimport scipy.stats as scs\ndef pearsonr(x,y): return scs.pearsonr(x,y)[0]\ndef MyPearsonCorrCoef(dim_argmax=None, **kwargs):\n    \"Pearson correlation coefficient for regression problem\"\n    return AccumMetric(pearsonr, invert_arg=False, dim_argmax=dim_argmax, **kwargs)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:01:18.224868Z","iopub.execute_input":"2025-09-12T15:01:18.225354Z","iopub.status.idle":"2025-09-12T15:01:18.229522Z","shell.execute_reply.started":"2025-09-12T15:01:18.225334Z","shell.execute_reply":"2025-09-12T15:01:18.228776Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pearson = MyPearsonCorrCoef()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:01:18.230284Z","iopub.execute_input":"2025-09-12T15:01:18.230537Z","iopub.status.idle":"2025-09-12T15:01:18.247391Z","shell.execute_reply.started":"2025-09-12T15:01:18.230517Z","shell.execute_reply":"2025-09-12T15:01:18.246604Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"learn = tabular_learner(dls, metrics=pearson)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:03:06.752803Z","iopub.execute_input":"2025-09-12T15:03:06.753113Z","iopub.status.idle":"2025-09-12T15:03:06.783836Z","shell.execute_reply.started":"2025-09-12T15:03:06.753092Z","shell.execute_reply":"2025-09-12T15:03:06.783180Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"learn.model","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:03:08.826460Z","iopub.execute_input":"2025-09-12T15:03:08.826720Z","iopub.status.idle":"2025-09-12T15:03:08.831936Z","shell.execute_reply.started":"2025-09-12T15:03:08.826699Z","shell.execute_reply":"2025-09-12T15:03:08.831243Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def replace_relu_to_lrelu(model):\n    for child_name, child in model.named_children():\n        if isinstance(child, nn.ReLU):\n            setattr(model, child_name, nn.LeakyReLU())\n        else:\n            # recurse\n            replace_relu_to_lrelu(child)\n\nreplace_relu_to_lrelu(learn.model)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:03:29.183204Z","iopub.execute_input":"2025-09-12T15:03:29.183476Z","iopub.status.idle":"2025-09-12T15:03:29.187870Z","shell.execute_reply.started":"2025-09-12T15:03:29.183457Z","shell.execute_reply":"2025-09-12T15:03:29.187086Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"learn.lr_find(suggest_funcs=(slide, valley))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:03:31.905106Z","iopub.execute_input":"2025-09-12T15:03:31.905752Z","iopub.status.idle":"2025-09-12T15:03:34.001480Z","shell.execute_reply.started":"2025-09-12T15:03:31.905725Z","shell.execute_reply":"2025-09-12T15:03:34.000626Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"learn.fit_one_cycle(2, 0.001)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:03:39.574206Z","iopub.execute_input":"2025-09-12T15:03:39.574480Z","iopub.status.idle":"2025-09-12T15:05:33.925821Z","shell.execute_reply.started":"2025-09-12T15:03:39.574459Z","shell.execute_reply":"2025-09-12T15:05:33.925226Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"learn.model","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:05:51.413927Z","iopub.execute_input":"2025-09-12T15:05:51.414223Z","iopub.status.idle":"2025-09-12T15:05:51.419516Z","shell.execute_reply.started":"2025-09-12T15:05:51.414203Z","shell.execute_reply":"2025-09-12T15:05:51.418925Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"learn.export('/kaggle/working/drw_newdata_fastai_lr_optimized_model_lrelu.pkl')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:06:12.676230Z","iopub.execute_input":"2025-09-12T15:06:12.676917Z","iopub.status.idle":"2025-09-12T15:06:12.940113Z","shell.execute_reply.started":"2025-09-12T15:06:12.676865Z","shell.execute_reply":"2025-09-12T15:06:12.939373Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_table  = pq.read_pandas(base_path/\"test.parquet\")\ntest_df = test_table.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:06:14.743395Z","iopub.execute_input":"2025-09-12T15:06:14.743656Z","iopub.status.idle":"2025-09-12T15:06:24.278203Z","shell.execute_reply.started":"2025-09-12T15:06:14.743636Z","shell.execute_reply":"2025-09-12T15:06:24.277704Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"    to = TabularPandas(test_df,\n           # procs=[Normalize],\n           cont_names = train_cols,\n           y_names='label')\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:06:26.111765Z","iopub.execute_input":"2025-09-12T15:06:26.112453Z","iopub.status.idle":"2025-09-12T15:06:33.011103Z","shell.execute_reply.started":"2025-09-12T15:06:26.112422Z","shell.execute_reply":"2025-09-12T15:06:33.010195Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"    dl = learn.dls.test_dl(to.xs, bs=64)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:06:33.012329Z","iopub.execute_input":"2025-09-12T15:06:33.012596Z","iopub.status.idle":"2025-09-12T15:06:39.814833Z","shell.execute_reply.started":"2025-09-12T15:06:33.012570Z","shell.execute_reply":"2025-09-12T15:06:39.810775Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"    preds, _ = learn.get_preds(dl=dl)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:06:53.599986Z","iopub.execute_input":"2025-09-12T15:06:53.600253Z","iopub.status.idle":"2025-09-12T15:07:17.572679Z","shell.execute_reply.started":"2025-09-12T15:06:53.600233Z","shell.execute_reply":"2025-09-12T15:07:17.571909Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub_df = pd.DataFrame()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:07:29.430464Z","iopub.execute_input":"2025-09-12T15:07:29.430727Z","iopub.status.idle":"2025-09-12T15:07:29.435015Z","shell.execute_reply.started":"2025-09-12T15:07:29.430707Z","shell.execute_reply":"2025-09-12T15:07:29.434329Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"    sub_df[\"ID\"] = to.xs.index\n    sub_df['prediction'] = preds\n    sub_df.to_csv(\"/kaggle/working/submission_newdata_fastai_tabular_lr_optimized_lrelu.csv\", header=True, index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-12T15:07:29.637292Z","iopub.execute_input":"2025-09-12T15:07:29.637489Z","iopub.status.idle":"2025-09-12T15:07:31.304815Z","shell.execute_reply.started":"2025-09-12T15:07:29.637473Z","shell.execute_reply":"2025-09-12T15:07:31.303954Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}