{"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":"import pandas as pd\nimport numpy as np\nfrom datetime import datetime","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:31:49.827013Z","iopub.execute_input":"2021-12-11T14:31:49.827431Z","iopub.status.idle":"2021-12-11T14:31:49.853344Z","shell.execute_reply.started":"2021-12-11T14:31:49.827313Z","shell.execute_reply":"2021-12-11T14:31:49.852511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"crypto_df = pd.read_csv(\"../input/g-research-crypto-forecasting/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:31:49.854788Z","iopub.execute_input":"2021-12-11T14:31:49.855212Z","iopub.status.idle":"2021-12-11T14:32:44.215438Z","shell.execute_reply.started":"2021-12-11T14:31:49.85517Z","shell.execute_reply":"2021-12-11T14:32:44.214525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"crypto_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.216603Z","iopub.execute_input":"2021-12-11T14:32:44.216825Z","iopub.status.idle":"2021-12-11T14:32:44.241567Z","shell.execute_reply.started":"2021-12-11T14:32:44.2168Z","shell.execute_reply":"2021-12-11T14:32:44.240943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"assest_details = pd.read_csv(\"../input/g-research-crypto-forecasting/asset_details.csv\")\nassest_details","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.24297Z","iopub.execute_input":"2021-12-11T14:32:44.243664Z","iopub.status.idle":"2021-12-11T14:32:44.259494Z","shell.execute_reply.started":"2021-12-11T14:32:44.243621Z","shell.execute_reply":"2021-12-11T14:32:44.258906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bitcoin_df = crypto_df[crypto_df[\"Asset_ID\"] == 1].set_index(\"timestamp\")","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.260311Z","iopub.execute_input":"2021-12-11T14:32:44.260791Z","iopub.status.idle":"2021-12-11T14:32:44.548916Z","shell.execute_reply.started":"2021-12-11T14:32:44.260762Z","shell.execute_reply":"2021-12-11T14:32:44.548133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bitcoin_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.55012Z","iopub.execute_input":"2021-12-11T14:32:44.55033Z","iopub.status.idle":"2021-12-11T14:32:44.567255Z","shell.execute_reply.started":"2021-12-11T14:32:44.550305Z","shell.execute_reply":"2021-12-11T14:32:44.566355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bitcoin_df.info(show_counts = True)","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.568559Z","iopub.execute_input":"2021-12-11T14:32:44.568854Z","iopub.status.idle":"2021-12-11T14:32:44.622347Z","shell.execute_reply.started":"2021-12-11T14:32:44.568803Z","shell.execute_reply":"2021-12-11T14:32:44.621507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bitcoin_df.Target.isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.623757Z","iopub.execute_input":"2021-12-11T14:32:44.624231Z","iopub.status.idle":"2021-12-11T14:32:44.644646Z","shell.execute_reply.started":"2021-12-11T14:32:44.62419Z","shell.execute_reply":"2021-12-11T14:32:44.643827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bitcoin_df = bitcoin_df.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.647258Z","iopub.execute_input":"2021-12-11T14:32:44.647707Z","iopub.status.idle":"2021-12-11T14:32:44.706267Z","shell.execute_reply.started":"2021-12-11T14:32:44.647667Z","shell.execute_reply":"2021-12-11T14:32:44.705419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bitcoin_df.Target.isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.707418Z","iopub.execute_input":"2021-12-11T14:32:44.707632Z","iopub.status.idle":"2021-12-11T14:32:44.725301Z","shell.execute_reply.started":"2021-12-11T14:32:44.707606Z","shell.execute_reply":"2021-12-11T14:32:44.724736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bitcoin_df.info(show_counts = True)","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.726499Z","iopub.execute_input":"2021-12-11T14:32:44.726742Z","iopub.status.idle":"2021-12-11T14:32:44.773878Z","shell.execute_reply.started":"2021-12-11T14:32:44.726715Z","shell.execute_reply":"2021-12-11T14:32:44.773029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(bitcoin_df.index[1:] - bitcoin_df.index[:-1]).value_counts()\n\n#reindex - fill the values","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.775268Z","iopub.execute_input":"2021-12-11T14:32:44.775708Z","iopub.status.idle":"2021-12-11T14:32:44.802172Z","shell.execute_reply.started":"2021-12-11T14:32:44.775667Z","shell.execute_reply":"2021-12-11T14:32:44.801188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = bitcoin_df.drop(columns = ['Target'])\ny = bitcoin_df.Target","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.803276Z","iopub.execute_input":"2021-12-11T14:32:44.803473Z","iopub.status.idle":"2021-12-11T14:32:44.834878Z","shell.execute_reply.started":"2021-12-11T14:32:44.803449Z","shell.execute_reply":"2021-12-11T14:32:44.834201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainCount = int(len(y) * 0.8)\ntrainCount","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.835765Z","iopub.execute_input":"2021-12-11T14:32:44.836613Z","iopub.status.idle":"2021-12-11T14:32:44.850484Z","shell.execute_reply.started":"2021-12-11T14:32:44.836572Z","shell.execute_reply":"2021-12-11T14:32:44.849541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = X[:trainCount], X[trainCount: ], y[:trainCount], y[trainCount:]","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.85164Z","iopub.execute_input":"2021-12-11T14:32:44.852231Z","iopub.status.idle":"2021-12-11T14:32:44.861129Z","shell.execute_reply.started":"2021-12-11T14:32:44.852187Z","shell.execute_reply":"2021-12-11T14:32:44.86046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\n\nlr = LinearRegression()\n\nlr.fit(X_train, y_train)\ny_pred = lr.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:44.862453Z","iopub.execute_input":"2021-12-11T14:32:44.862938Z","iopub.status.idle":"2021-12-11T14:32:46.435232Z","shell.execute_reply.started":"2021-12-11T14:32:44.862895Z","shell.execute_reply":"2021-12-11T14:32:46.434214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from scipy.stats import pearsonr\n\npearsonr(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:32:46.437167Z","iopub.execute_input":"2021-12-11T14:32:46.437813Z","iopub.status.idle":"2021-12-11T14:32:46.456662Z","shell.execute_reply.started":"2021-12-11T14:32:46.437759Z","shell.execute_reply":"2021-12-11T14:32:46.45582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datetime.fromtimestamp(X.index[0])","metadata":{"execution":{"iopub.status.busy":"2021-12-11T14:33:04.947646Z","iopub.execute_input":"2021-12-11T14:33:04.948257Z","iopub.status.idle":"2021-12-11T14:33:04.955992Z","shell.execute_reply.started":"2021-12-11T14:33:04.948209Z","shell.execute_reply":"2021-12-11T14:33:04.955374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}