{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84493,"databundleVersionId":9871156,"sourceType":"competition"},{"sourceId":10245336,"sourceType":"datasetVersion","datasetId":6336300},{"sourceId":10316890,"sourceType":"datasetVersion","datasetId":6387135}],"dockerImageVersionId":30822,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:07:01.361267Z","iopub.execute_input":"2024-12-28T07:07:01.361704Z","iopub.status.idle":"2024-12-28T07:07:02.046862Z","shell.execute_reply.started":"2024-12-28T07:07:01.361662Z","shell.execute_reply":"2024-12-28T07:07:02.045617Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import polars as pl\nfrom sklearn.metrics import r2_score","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:07:09.611832Z","iopub.execute_input":"2024-12-28T07:07:09.612241Z","iopub.status.idle":"2024-12-28T07:07:09.617023Z","shell.execute_reply.started":"2024-12-28T07:07:09.612211Z","shell.execute_reply":"2024-12-28T07:07:09.615976Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pl.scan_parquet(\n    f\"/kaggle/input/20241219-data/training.parquet\"\n).collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:07:09.961836Z","iopub.execute_input":"2024-12-28T07:07:09.962207Z","iopub.status.idle":"2024-12-28T07:07:19.032191Z","shell.execute_reply.started":"2024-12-28T07:07:09.962179Z","shell.execute_reply":"2024-12-28T07:07:19.030854Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = train.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:07:19.034170Z","iopub.execute_input":"2024-12-28T07:07:19.034634Z","iopub.status.idle":"2024-12-28T07:07:25.806350Z","shell.execute_reply.started":"2024-12-28T07:07:19.034590Z","shell.execute_reply":"2024-12-28T07:07:25.805209Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val= pl.scan_parquet(\n    f\"/kaggle/input/20241219-data/validation.parquet\"\n).collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:25.332217Z","iopub.execute_input":"2024-12-28T07:08:25.332551Z","iopub.status.idle":"2024-12-28T07:08:26.243253Z","shell.execute_reply.started":"2024-12-28T07:08:25.332526Z","shell.execute_reply":"2024-12-28T07:08:26.242179Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val = val.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:26.244645Z","iopub.execute_input":"2024-12-28T07:08:26.245009Z","iopub.status.idle":"2024-12-28T07:08:26.758561Z","shell.execute_reply.started":"2024-12-28T07:08:26.244980Z","shell.execute_reply":"2024-12-28T07:08:26.757489Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:26.760372Z","iopub.execute_input":"2024-12-28T07:08:26.760801Z","iopub.status.idle":"2024-12-28T07:08:27.791286Z","shell.execute_reply.started":"2024-12-28T07:08:26.760757Z","shell.execute_reply":"2024-12-28T07:08:27.790077Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:27.792943Z","iopub.execute_input":"2024-12-28T07:08:27.793342Z","iopub.status.idle":"2024-12-28T07:08:27.816976Z","shell.execute_reply.started":"2024-12-28T07:08:27.793311Z","shell.execute_reply":"2024-12-28T07:08:27.815383Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_offline = train[-180:]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:27.818529Z","iopub.execute_input":"2024-12-28T07:08:27.818895Z","iopub.status.idle":"2024-12-28T07:08:27.837511Z","shell.execute_reply.started":"2024-12-28T07:08:27.818867Z","shell.execute_reply":"2024-12-28T07:08:27.836230Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_offline","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:27.838710Z","iopub.execute_input":"2024-12-28T07:08:27.839110Z","iopub.status.idle":"2024-12-28T07:08:27.885313Z","shell.execute_reply.started":"2024-12-28T07:08:27.839075Z","shell.execute_reply":"2024-12-28T07:08:27.883820Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 拿全部的数据集做预测","metadata":{}},{"cell_type":"code","source":"val['pre_responder_6'] = train['responder_6_lag_1'].median()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:27.887667Z","iopub.execute_input":"2024-12-28T07:08:27.888087Z","iopub.status.idle":"2024-12-28T07:08:28.022247Z","shell.execute_reply.started":"2024-12-28T07:08:27.888013Z","shell.execute_reply":"2024-12-28T07:08:28.020942Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:28.023485Z","iopub.execute_input":"2024-12-28T07:08:28.023770Z","iopub.status.idle":"2024-12-28T07:08:28.218289Z","shell.execute_reply.started":"2024-12-28T07:08:28.023747Z","shell.execute_reply":"2024-12-28T07:08:28.217159Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 拿后180天数据集做预测","metadata":{}},{"cell_type":"code","source":"val['responder_6_pred'] = train_offline['responder_6_lag_1'].median()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:28.219886Z","iopub.execute_input":"2024-12-28T07:08:28.220324Z","iopub.status.idle":"2024-12-28T07:08:28.229011Z","shell.execute_reply.started":"2024-12-28T07:08:28.220281Z","shell.execute_reply":"2024-12-28T07:08:28.227690Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:33.957228Z","iopub.execute_input":"2024-12-28T07:08:33.957617Z","iopub.status.idle":"2024-12-28T07:08:34.181726Z","shell.execute_reply.started":"2024-12-28T07:08:33.957586Z","shell.execute_reply":"2024-12-28T07:08:34.180598Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def t_f_mul(y_true, y_pred , weight):\n    return (y_true - y_pred)*(y_true - y_pred)*weight\ndef t_mul(y_true,weight):\n    return y_true*y_true*weight\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:34.849725Z","iopub.execute_input":"2024-12-28T07:08:34.850136Z","iopub.status.idle":"2024-12-28T07:08:34.856721Z","shell.execute_reply.started":"2024-12-28T07:08:34.850100Z","shell.execute_reply":"2024-12-28T07:08:34.855005Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"f_sum = val.apply(lambda row : t_f_mul(row['responder_6_lag_1'],row['responder_6_pred'],row['weight']),axis=1).sum()\ns_sum = val.apply(lambda row : t_mul(row['responder_6_lag_1'],row['weight']),axis=1).sum()\nscore1 = 1 - f_sum/s_sum","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:35.053860Z","iopub.execute_input":"2024-12-28T07:08:35.054266Z","iopub.status.idle":"2024-12-28T07:08:49.564725Z","shell.execute_reply.started":"2024-12-28T07:08:35.054231Z","shell.execute_reply":"2024-12-28T07:08:49.563566Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"score1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:49.566315Z","iopub.execute_input":"2024-12-28T07:08:49.566716Z","iopub.status.idle":"2024-12-28T07:08:49.572947Z","shell.execute_reply.started":"2024-12-28T07:08:49.566684Z","shell.execute_reply":"2024-12-28T07:08:49.571952Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"f_sum = val.apply(lambda row : t_f_mul(row['responder_6_lag_1'],row['pre_responder_6'],row['weight']),axis=1).sum()\ns_sum = val.apply(lambda row : t_mul(row['responder_6_lag_1'],row['weight']),axis=1).sum()\nscore2 = 1 - f_sum/s_sum","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:08:49.574876Z","iopub.execute_input":"2024-12-28T07:08:49.575285Z","iopub.status.idle":"2024-12-28T07:09:04.264605Z","shell.execute_reply.started":"2024-12-28T07:08:49.575255Z","shell.execute_reply":"2024-12-28T07:09:04.263551Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"score2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:09:04.266107Z","iopub.execute_input":"2024-12-28T07:09:04.266433Z","iopub.status.idle":"2024-12-28T07:09:04.272862Z","shell.execute_reply.started":"2024-12-28T07:09:04.266393Z","shell.execute_reply":"2024-12-28T07:09:04.271663Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 生成的dataset","metadata":{}},{"cell_type":"code","source":"train = pl.scan_parquet(\n    f\"/kaggle/input/dataset-1219/training.parquet\"\n).collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:09:04.274075Z","iopub.execute_input":"2024-12-28T07:09:04.274476Z","iopub.status.idle":"2024-12-28T07:09:07.922126Z","shell.execute_reply.started":"2024-12-28T07:09:04.274445Z","shell.execute_reply":"2024-12-28T07:09:07.920933Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = train.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:09:07.923260Z","iopub.execute_input":"2024-12-28T07:09:07.923677Z","iopub.status.idle":"2024-12-28T07:09:13.384438Z","shell.execute_reply.started":"2024-12-28T07:09:07.923637Z","shell.execute_reply":"2024-12-28T07:09:13.383069Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val = pl.scan_parquet(\n    f\"/kaggle/input/dataset-1219/validation.parquet\"\n).collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:09:13.386082Z","iopub.execute_input":"2024-12-28T07:09:13.386601Z","iopub.status.idle":"2024-12-28T07:09:13.807993Z","shell.execute_reply.started":"2024-12-28T07:09:13.386544Z","shell.execute_reply":"2024-12-28T07:09:13.806742Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val = val.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:09:13.810575Z","iopub.execute_input":"2024-12-28T07:09:13.810898Z","iopub.status.idle":"2024-12-28T07:09:14.149993Z","shell.execute_reply.started":"2024-12-28T07:09:13.810872Z","shell.execute_reply":"2024-12-28T07:09:14.148454Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:09:14.151729Z","iopub.execute_input":"2024-12-28T07:09:14.152178Z","iopub.status.idle":"2024-12-28T07:09:14.174118Z","shell.execute_reply.started":"2024-12-28T07:09:14.152145Z","shell.execute_reply":"2024-12-28T07:09:14.172753Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T07:09:14.175344Z","iopub.execute_input":"2024-12-28T07:09:14.175720Z","iopub.status.idle":"2024-12-28T07:09:14.211463Z","shell.execute_reply.started":"2024-12-28T07:09:14.175680Z","shell.execute_reply":"2024-12-28T07:09:14.209966Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}