{"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":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Reference**\n","metadata":{}},{"cell_type":"markdown","source":"*  https://www.kaggle.com/axzhang/s-baseline-lgb-reproduce-the-lb-score\n* https://www.kaggle.com/jiny333/creating-whl-files-to-install-external-libraries","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"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\nimport pickle","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-05T16:18:29.918919Z","iopub.execute_input":"2022-01-05T16:18:29.919543Z","iopub.status.idle":"2022-01-05T16:18:30.002024Z","shell.execute_reply.started":"2022-01-05T16:18:29.919411Z","shell.execute_reply":"2022-01-05T16:18:30.001281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gresearch_crypto\nimport datetime as dt","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:18:30.00333Z","iopub.execute_input":"2022-01-05T16:18:30.00356Z","iopub.status.idle":"2022-01-05T16:18:30.027766Z","shell.execute_reply.started":"2022-01-05T16:18:30.003531Z","shell.execute_reply":"2022-01-05T16:18:30.027046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --no-index --no-deps ../input/prophet/wheelhouse/*.whl","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:18:30.029071Z","iopub.execute_input":"2022-01-05T16:18:30.029488Z","iopub.status.idle":"2022-01-05T16:18:34.603459Z","shell.execute_reply.started":"2022-01-05T16:18:30.029454Z","shell.execute_reply":"2022-01-05T16:18:34.602262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip uninstall -y pystan ","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:18:34.606513Z","iopub.execute_input":"2022-01-05T16:18:34.60714Z","iopub.status.idle":"2022-01-05T16:19:02.820018Z","shell.execute_reply.started":"2022-01-05T16:18:34.607086Z","shell.execute_reply":"2022-01-05T16:19:02.818897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --no-index --no-deps ../input/pystan/wheelhouse/*.whl","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:19:02.821904Z","iopub.execute_input":"2022-01-05T16:19:02.822135Z","iopub.status.idle":"2022-01-05T16:19:37.176477Z","shell.execute_reply.started":"2022-01-05T16:19:02.822104Z","shell.execute_reply":"2022-01-05T16:19:37.175676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fbprophet import Prophet","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:19:37.178426Z","iopub.execute_input":"2022-01-05T16:19:37.179037Z","iopub.status.idle":"2022-01-05T16:19:37.603157Z","shell.execute_reply.started":"2022-01-05T16:19:37.178994Z","shell.execute_reply":"2022-01-05T16:19:37.602391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\ntrain = pd.read_csv(\"../input/g-research-crypto-forecasting/train.csv\")\ntrain['timestamp'] = pd.to_datetime(train['timestamp'],unit='s')\ntrain = train.rename(columns={'timestamp': 'ds',\"Target\":\"y\"})\ntrain = train[train[\"y\"].isnull()==0]\ntrain = train[train['ds'] > dt.datetime(2020,9,1)]\n\nfeature_cols = [\"ds\",\"Close\",\"y\",\"Asset_ID\"]\ntrain = train[feature_cols]\n\nm0 = Prophet()\nm1 = Prophet()\nm2 = Prophet()\nm3 = Prophet()\nm4 = Prophet()\nm5 = Prophet()\nm6 = Prophet()\nm7 = Prophet()\nm8 = Prophet()\nm9 = Prophet()\nm10 = Prophet()\nm11 = Prophet()\nm12 = Prophet()\nm13 = Prophet()\n\nmodels = {0: m0,\n 1: m1,\n 2: m2,\n 3: m3,\n 4: m4,\n 5: m5,\n 6: m6,\n 7: m7,\n 8: m8,\n 9: m9,\n 10: m10,\n 11: m11,\n 12: m12,\n 13: m13}\n\nfor i in range(14):\n    models[i].fit(train[train[\"Asset_ID\"]==i][[\"ds\",\"Close\",\"y\"]])\n    pkl_model_path = './prophet-model{0}.pkl'.format(i)\n    with open(pkl_model_path, 'wb') as f:\n        pickle.dump(models[i], f)\"\"\"","metadata":{"execution":{"iopub.status.busy":"2022-01-05T16:19:37.604393Z","iopub.execute_input":"2022-01-05T16:19:37.605108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nwith open('../input/fbp-model/prophet-model0.pkl', 'rb') as f:\n    m0 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model1.pkl', 'rb') as f:\n    m1 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model2.pkl', 'rb') as f:\n    m2 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model3.pkl', 'rb') as f:\n    m3 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model4.pkl', 'rb') as f:\n    m4 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model5.pkl', 'rb') as f:\n    m5 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model6.pkl', 'rb') as f:\n    m6 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model7.pkl', 'rb') as f:\n    m7 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model8.pkl', 'rb') as f:\n    m8 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model9.pkl', 'rb') as f:\n    m9 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model10.pkl', 'rb') as f:\n    m10 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model11.pkl', 'rb') as f:\n    m11 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model12.pkl', 'rb') as f:\n    m12 = pickle.load(f)\nwith open('../input/fbp-model/prophet-model13.pkl', 'rb') as f:\n    m13 = pickle.load(f)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"models = {0: m0,\n 1: m1,\n 2: m2,\n 3: m3,\n 4: m4,\n 5: m5,\n 6: m6,\n 7: m7,\n 8: m8,\n 9: m9,\n 10: m10,\n 11: m11,\n 12: m12,\n 13: m13}","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_cols = [\"ds\",\"Close\"]\nenv = gresearch_crypto.make_env()\niter_test = env.iter_test()\n\nfor i, (df_test, df_pred) in enumerate(iter_test):\n    df_test['timestamp'] = pd.to_datetime(df_test['timestamp'],unit='s')\n    df_test = df_test.rename(columns={'timestamp': 'ds'})\n    for j , row in df_test.iterrows():\n        model = models[row['Asset_ID']]\n        x_test = pd.DataFrame(row).T\n        y_pred = model.predict(x_test[feature_cols])[\"yhat\"][0]\n\n        df_pred.loc[df_pred['row_id'] == row['row_id'], 'Target'] = y_pred\n        \n        \n        # Print just one sample row to get a feeling of what it looks like\n\n\n    # Display the first prediction dataframe\n\n        \n\n    # Send submissions\n    env.predict(df_pred)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}