{"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":"markdown","source":"## GResearch Crypto Forecasting\n### Introduction\nIn this competition you will forecast the prices of several cyrptoassets. Once you make that prediction, you can move on to the next batch and will get additional data.\n\nThis competition is different from most Kaggle Competitions in that:\n* You can only submit from Kaggle Notebooks\n* You must use our custom `gresearch_crypto` Python module.  The purpose of this module is to control the flow of information to ensure that you are not using future data to make predictions.  If you do not use this module properly, your code may fail.\n\n### This starter notebook demonstrates how to use the `gresearch_crypto` module to get the test features and make predictions.\n### TL;DR: End-to-End Usage Example\n```\nimport gresearch_crypto\nenv = gresearch_crypto.make_env()\n\n# Training data is in the competition dataset as usual\ntrain_df = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/train.csv', low_memory=False)\ntgt_1_model.fit(train_df)\ntgt_2_model.fit(train_df)\niter_test = env.iter_test()\nfor (test_df, sample_prediction_df) in iter_test:\n    sample_prediction_df['Target'] = tgt_1_model.predict(test_df)\n    env.predict(sample_prediction_df)\n```\nNote that `tgt_1_model.fit` and `tgt_2_model.fit` are examples of the functions you need to write for the above example to work.","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":0.010991,"end_time":"2020-10-16T21:06:02.406829","exception":false,"start_time":"2020-10-16T21:06:02.395838","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"### Introduction\nFirst let's import the module and create an environment. Adding the directory holding the module to the pythonpath with `sys.path.append` isn't strictly necessary within Kaggle notebooks, which handles that behind the scenes, but will be necessary if you are testing your code offline.","metadata":{"papermill":{"duration":0.009526,"end_time":"2020-10-16T21:06:02.426349","exception":false,"start_time":"2020-10-16T21:06:02.416823","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import gresearch_crypto\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:31:47.673132Z","iopub.execute_input":"2021-12-02T11:31:47.673636Z","iopub.status.idle":"2021-12-02T11:31:47.723262Z","shell.execute_reply.started":"2021-12-02T11:31:47.673550Z","shell.execute_reply":"2021-12-02T11:31:47.722550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"You can only call make_env() **once**, so don't lose it!","metadata":{}},{"cell_type":"code","source":"env = gresearch_crypto.make_env()","metadata":{"papermill":{"duration":0.02778,"end_time":"2020-10-16T21:06:02.463894","exception":false,"start_time":"2020-10-16T21:06:02.436114","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-12-02T11:31:47.724665Z","iopub.execute_input":"2021-12-02T11:31:47.724999Z","iopub.status.idle":"2021-12-02T11:31:47.729300Z","shell.execute_reply.started":"2021-12-02T11:31:47.724972Z","shell.execute_reply":"2021-12-02T11:31:47.728522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"papermill":{"duration":0.020032,"end_time":"2020-10-16T21:06:02.494341","exception":false,"start_time":"2020-10-16T21:06:02.474309","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-12-02T11:31:47.730265Z","iopub.execute_input":"2021-12-02T11:31:47.730813Z","iopub.status.idle":"2021-12-02T11:31:47.745600Z","shell.execute_reply.started":"2021-12-02T11:31:47.730786Z","shell.execute_reply":"2021-12-02T11:31:47.744489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Training data is in the competition dataset as usual","metadata":{"papermill":{"duration":0.011622,"end_time":"2020-10-16T21:06:02.516712","exception":false,"start_time":"2020-10-16T21:06:02.50509","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# You can only iterate through a result from `env.iter_test()` once\n# so be careful not to lose it once you start iterating.\niter_test = env.iter_test()","metadata":{"papermill":{"duration":0.018224,"end_time":"2020-10-16T21:06:02.851885","exception":false,"start_time":"2020-10-16T21:06:02.833661","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-12-02T11:32:34.350314Z","iopub.execute_input":"2021-12-02T11:32:34.350645Z","iopub.status.idle":"2021-12-02T11:32:34.355928Z","shell.execute_reply.started":"2021-12-02T11:32:34.350615Z","shell.execute_reply":"2021-12-02T11:32:34.354707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for (test_df, sample_prediction_df) in iter_test:\n    sample_prediction_df['Target'] = test_df['Volume']\n    env.predict(sample_prediction_df)","metadata":{"papermill":{"duration":0.363455,"end_time":"2020-10-16T21:06:03.522581","exception":false,"start_time":"2020-10-16T21:06:03.159126","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-12-02T11:32:34.845304Z","iopub.execute_input":"2021-12-02T11:32:34.845925Z","iopub.status.idle":"2021-12-02T11:32:34.899732Z","shell.execute_reply.started":"2021-12-02T11:32:34.845883Z","shell.execute_reply":"2021-12-02T11:32:34.898618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Restart the Notebook to run your code again\nIn order to combat cheating you are only allowed to call `make_env` or iterate through `iter_test` once per Notebook run.  However, while you're iterating on your model it's reasonable to try something out, change the model a bit, and try it again.  Unfortunately, if you try to simply re-run the code, or even refresh the browser page, you'll still be running on the same Notebook execution session you had been running before, and the `gresearch_crypto` module will still throw errors.  To get around this you need to explicitly restart your Notebook execution session.","metadata":{"papermill":{"duration":0.013013,"end_time":"2020-10-16T21:06:03.549216","exception":false,"start_time":"2020-10-16T21:06:03.536203","status":"completed"},"tags":[]}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}