{"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":"This notebook provides the absolute minimum code necessary for making a submission and is meant for copying into your own pipeline. If you're looking for a more detailed explanation of how the API works, take a look at [this notebook instead](https://www.kaggle.com/sohier/detailed-api-introduction).","metadata":{}},{"cell_type":"code","source":"import gresearch_crypto\nimport pandas as pd\nimport numpy as np\nimport lightgbm as lgb\nfrom numpy import arange\nfrom sklearn.linear_model import Ridge\nfrom sklearn.linear_model import ElasticNet\nfrom sklearn.preprocessing import RobustScaler\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.model_selection import RepeatedKFold\nfrom scipy.stats import pearsonr","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:17.802185Z","iopub.execute_input":"2021-11-03T07:29:17.802459Z","iopub.status.idle":"2021-11-03T07:29:17.809323Z","shell.execute_reply.started":"2021-11-03T07:29:17.802433Z","shell.execute_reply":"2021-11-03T07:29:17.808441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CFG:\n    nof_trees = 100","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:17.811486Z","iopub.execute_input":"2021-11-03T07:29:17.812067Z","iopub.status.idle":"2021-11-03T07:29:17.821982Z","shell.execute_reply.started":"2021-11-03T07:29:17.812024Z","shell.execute_reply":"2021-11-03T07:29:17.821204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Functions","metadata":{}},{"cell_type":"code","source":"def process_data(df):\n    return 0","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:17.823251Z","iopub.execute_input":"2021-11-03T07:29:17.823672Z","iopub.status.idle":"2021-11-03T07:29:17.83452Z","shell.execute_reply.started":"2021-11-03T07:29:17.823635Z","shell.execute_reply":"2021-11-03T07:29:17.833779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data","metadata":{}},{"cell_type":"code","source":"df_train = pd.read_csv('../input/g-research-crypto-forecasting/train.csv')\n\nxte = pd.read_csv('../input/g-research-crypto-forecasting/example_test.csv')\n","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:17.835823Z","iopub.execute_input":"2021-11-03T07:29:17.83628Z","iopub.status.idle":"2021-11-03T07:29:48.319804Z","shell.execute_reply.started":"2021-11-03T07:29:17.836249Z","shell.execute_reply":"2021-11-03T07:29:48.319171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_cols = ['Asset_ID', 'Close', 'Count', 'High', 'Low', 'Open', 'VWAP',\n       'Volume', 'timestamp']","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:48.321943Z","iopub.execute_input":"2021-11-03T07:29:48.322184Z","iopub.status.idle":"2021-11-03T07:29:48.325984Z","shell.execute_reply.started":"2021-11-03T07:29:48.322156Z","shell.execute_reply":"2021-11-03T07:29:48.325225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.dropna(axis = 0, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:48.327145Z","iopub.execute_input":"2021-11-03T07:29:48.327936Z","iopub.status.idle":"2021-11-03T07:29:50.344619Z","shell.execute_reply.started":"2021-11-03T07:29:48.327897Z","shell.execute_reply":"2021-11-03T07:29:50.343986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model","metadata":{}},{"cell_type":"code","source":"ytrain = df_train['Target'].copy()\nxtrain = df_train[feature_cols].copy()","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:50.345635Z","iopub.execute_input":"2021-11-03T07:29:50.346513Z","iopub.status.idle":"2021-11-03T07:29:51.609451Z","shell.execute_reply.started":"2021-11-03T07:29:50.346474Z","shell.execute_reply":"2021-11-03T07:29:51.608655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_size = int(0.9 * xtrain.shape[0])\nx0, y0 = xtrain.iloc[:train_size],ytrain.iloc[:train_size]\nx1, y1 = xtrain.iloc[train_size:],ytrain.iloc[train_size:]","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:51.610883Z","iopub.execute_input":"2021-11-03T07:29:51.611334Z","iopub.status.idle":"2021-11-03T07:29:51.685316Z","shell.execute_reply.started":"2021-11-03T07:29:51.611306Z","shell.execute_reply":"2021-11-03T07:29:51.684221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col_subset = ['High', 'Low', 'Close', 'Open', 'Count','Volume']","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:51.686532Z","iopub.execute_input":"2021-11-03T07:29:51.686797Z","iopub.status.idle":"2021-11-03T07:29:51.697205Z","shell.execute_reply.started":"2021-11-03T07:29:51.68677Z","shell.execute_reply":"2021-11-03T07:29:51.69641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = ElasticNet()\ncv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)\ngrid = dict()\ngrid['alpha'] = [1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 0.0, 1.0, 10.0, 100.0]\ngrid['l1_ratio'] = arange(0, 1, 0.01)\nsearch = GridSearchCV(model, grid, scoring='neg_mean_absolute_error', cv=cv, n_jobs=-1)\n\nx0a = pd.get_dummies(x0['Asset_ID'])\nx1a = pd.get_dummies(x1['Asset_ID'])\nmodel.fit(x0[col_subset],y0)","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:51.698393Z","iopub.execute_input":"2021-11-03T07:29:51.698604Z","iopub.status.idle":"2021-11-03T07:29:54.23406Z","shell.execute_reply.started":"2021-11-03T07:29:51.69858Z","shell.execute_reply":"2021-11-03T07:29:54.233164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(x1[col_subset])","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:54.235666Z","iopub.execute_input":"2021-11-03T07:29:54.236166Z","iopub.status.idle":"2021-11-03T07:29:54.32933Z","shell.execute_reply.started":"2021-11-03T07:29:54.236126Z","shell.execute_reply":"2021-11-03T07:29:54.328363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.corrcoef(y1,pred)","metadata":{"execution":{"iopub.status.busy":"2021-11-03T07:29:54.334861Z","iopub.execute_input":"2021-11-03T07:29:54.335728Z","iopub.status.idle":"2021-11-03T07:29:54.411533Z","shell.execute_reply.started":"2021-11-03T07:29:54.335659Z","shell.execute_reply":"2021-11-03T07:29:54.410613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{}},{"cell_type":"code","source":"\nenv = gresearch_crypto.make_env()\niter_test = env.iter_test()\nfor (test_df, sample_prediction_df) in iter_test:\n    xte = test_df[col_subset]\n    sample_prediction_df['Target'] = model.predict(xte)\n    env.predict(sample_prediction_df)","metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","papermill":{"duration":0.025192,"end_time":"2020-10-19T15:08:36.590409","exception":false,"start_time":"2020-10-19T15:08:36.565217","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-11-03T07:29:54.417221Z","iopub.execute_input":"2021-11-03T07:29:54.419985Z","iopub.status.idle":"2021-11-03T07:29:54.467612Z","shell.execute_reply.started":"2021-11-03T07:29:54.419919Z","shell.execute_reply":"2021-11-03T07:29:54.466848Z"},"trusted":true},"execution_count":null,"outputs":[]}]}