{"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-02T11:48:22.399357Z","iopub.execute_input":"2021-12-02T11:48:22.399949Z","iopub.status.idle":"2021-12-02T11:48:22.426182Z","shell.execute_reply.started":"2021-12-02T11:48:22.399815Z","shell.execute_reply":"2021-12-02T11:48:22.425468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def weighted_correlation(a, b, weights):\n\n  w = np.ravel(weights)\n  a = np.ravel(a)\n  b = np.ravel(b)\n\n  sum_w = np.sum(w)\n  mean_a = np.sum(a * w) / sum_w\n  mean_b = np.sum(b * w) / sum_w\n  var_a = np.sum(w * np.square(a - mean_a)) / sum_w\n  var_b = np.sum(w * np.square(b - mean_b)) / sum_w\n\n  cov = np.sum((a * b * w)) / np.sum(w) - mean_a * mean_b\n  corr = cov / np.sqrt(var_a * var_b)\n\n  return corr","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:48:22.428129Z","iopub.execute_input":"2021-12-02T11:48:22.428591Z","iopub.status.idle":"2021-12-02T11:48:22.435169Z","shell.execute_reply.started":"2021-12-02T11:48:22.428557Z","shell.execute_reply":"2021-12-02T11:48:22.433985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"asset=pd.read_csv('../input/g-research-crypto-forecasting/asset_details.csv')\nasset.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:48:22.436699Z","iopub.execute_input":"2021-12-02T11:48:22.436991Z","iopub.status.idle":"2021-12-02T11:48:22.478693Z","shell.execute_reply.started":"2021-12-02T11:48:22.436959Z","shell.execute_reply":"2021-12-02T11:48:22.477418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"map=dict(zip(asset['Asset_ID'],asset['Weight']))\nmap","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:48:22.480294Z","iopub.execute_input":"2021-12-02T11:48:22.480572Z","iopub.status.idle":"2021-12-02T11:48:22.491689Z","shell.execute_reply.started":"2021-12-02T11:48:22.480540Z","shell.execute_reply":"2021-12-02T11:48:22.490471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"public_lb=pd.read_csv('../input/g-research-using-the-overlap-fully-lb-0-99/submission.csv')\npublic_lb.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:48:22.494542Z","iopub.execute_input":"2021-12-02T11:48:22.494807Z","iopub.status.idle":"2021-12-02T11:48:22.521881Z","shell.execute_reply.started":"2021-12-02T11:48:22.494777Z","shell.execute_reply":"2021-12-02T11:48:22.521063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=pd.read_csv('../input/g-research-crypto-forecasting/example_test.csv')\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:48:22.523194Z","iopub.execute_input":"2021-12-02T11:48:22.524415Z","iopub.status.idle":"2021-12-02T11:48:22.548134Z","shell.execute_reply.started":"2021-12-02T11:48:22.524347Z","shell.execute_reply":"2021-12-02T11:48:22.547451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Weight']=test['Asset_ID'].map(map)","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:48:22.549280Z","iopub.execute_input":"2021-12-02T11:48:22.549547Z","iopub.status.idle":"2021-12-02T11:48:22.561267Z","shell.execute_reply.started":"2021-12-02T11:48:22.549517Z","shell.execute_reply":"2021-12-02T11:48:22.560444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weighted_correlation(test['Volume'],public_lb['Target'],test['Weight'])","metadata":{"execution":{"iopub.status.busy":"2021-12-02T11:48:22.562721Z","iopub.execute_input":"2021-12-02T11:48:22.563827Z","iopub.status.idle":"2021-12-02T11:48:22.575455Z","shell.execute_reply.started":"2021-12-02T11:48:22.563782Z","shell.execute_reply":"2021-12-02T11:48:22.574409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}