{"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":"# 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\n\n# for 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","execution":{"iopub.status.busy":"2023-03-12T01:06:17.078503Z","iopub.execute_input":"2023-03-12T01:06:17.078963Z","iopub.status.idle":"2023-03-12T01:06:17.110492Z","shell.execute_reply.started":"2023-03-12T01:06:17.078884Z","shell.execute_reply":"2023-03-12T01:06:17.109683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nsys.path.insert(0, '/kaggle/input/nfl-src-3rd-place')","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:06:20.378222Z","iopub.execute_input":"2023-03-12T01:06:20.379376Z","iopub.status.idle":"2023-03-12T01:06:20.389369Z","shell.execute_reply.started":"2023-03-12T01:06:20.379298Z","shell.execute_reply":"2023-03-12T01:06:20.387736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install /kaggle/input/nfl-models1/einops-0.6.0-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:06:21.092980Z","iopub.execute_input":"2023-03-12T01:06:21.093433Z","iopub.status.idle":"2023-03-12T01:06:52.379021Z","shell.execute_reply.started":"2023-03-12T01:06:21.093394Z","shell.execute_reply":"2023-03-12T01:06:52.377838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ln -s /kaggle/input/nfl-models1 models\n!ln -s /kaggle/input/nfl-models1 /tmp/models\n!ls models","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:06:52.381388Z","iopub.execute_input":"2023-03-12T01:06:52.381799Z","iopub.status.idle":"2023-03-12T01:06:55.240149Z","shell.execute_reply.started":"2023-03-12T01:06:52.381755Z","shell.execute_reply":"2023-03-12T01:06:55.238888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python /kaggle/input/nfl-src-3rd-place/predict_test.py preprocess","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:06:55.241596Z","iopub.execute_input":"2023-03-12T01:06:55.241901Z","iopub.status.idle":"2023-03-12T01:08:02.927288Z","shell.execute_reply.started":"2023-03-12T01:06:55.241869Z","shell.execute_reply":"2023-03-12T01:08:02.925808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python /kaggle/input/nfl-src-3rd-place/predict_test.py predict_test_parallel","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:08:02.931161Z","iopub.execute_input":"2023-03-12T01:08:02.931482Z","iopub.status.idle":"2023-03-12T01:24:45.305821Z","shell.execute_reply.started":"2023-03-12T01:08:02.931448Z","shell.execute_reply":"2023-03-12T01:24:45.304432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import copy\nimport os\nimport random\nfrom collections import defaultdict\n\nimport numpy as np\nimport pandas as pd\nfrom tqdm import tqdm\nimport pickle","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:24:45.307750Z","iopub.execute_input":"2023-03-12T01:24:45.308173Z","iopub.status.idle":"2023-03-12T01:24:45.314587Z","shell.execute_reply.started":"2023-03-12T01:24:45.308128Z","shell.execute_reply":"2023-03-12T01:24:45.313448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls /tmp/nfl_test","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:24:45.316147Z","iopub.execute_input":"2023-03-12T01:24:45.316819Z","iopub.status.idle":"2023-03-12T01:24:46.310281Z","shell.execute_reply.started":"2023-03-12T01:24:45.316785Z","shell.execute_reply":"2023-03-12T01:24:46.309044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/nfl-player-contact-detection/sample_submission.csv')\n\npred_items = defaultdict(list)\nfor group in range(4):\n    for rank in range(2):\n        cur_pred_items = pickle.load(open(f'/tmp/nfl_test/result_pred_models{group+1}_{rank}.pkl', 'rb'))\n        for key, values in cur_pred_items.items():\n            pred_items[key] = pred_items[key] + values\n\npred_items_mean = {k: np.mean(v) for k, v in pred_items.items()}\npred_df = pd.DataFrame(pred_items_mean.items(), columns=['contact_id', 'pred']).set_index('contact_id', drop=True)\n\nsubmission_with_pred = sample_submission.join(pred_df, on='contact_id', how='left').fillna(-0.1)\nsubmission_with_pred['contact'] = (submission_with_pred['pred'] > 0.39).astype(np.int32)\nsubmission_with_pred[['contact_id', 'contact']].to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:25:05.885142Z","iopub.execute_input":"2023-03-12T01:25:05.885530Z","iopub.status.idle":"2023-03-12T01:25:07.485340Z","shell.execute_reply.started":"2023-03-12T01:25:05.885493Z","shell.execute_reply":"2023-03-12T01:25:07.484288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_with_pred['contact'].mean()","metadata":{"execution":{"iopub.status.busy":"2023-03-12T01:25:07.494599Z","iopub.execute_input":"2023-03-12T01:25:07.495216Z","iopub.status.idle":"2023-03-12T01:25:07.509035Z","shell.execute_reply.started":"2023-03-12T01:25:07.495181Z","shell.execute_reply":"2023-03-12T01:25:07.508040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-02-26T09:58:11.123518Z","iopub.execute_input":"2023-02-26T09:58:11.124826Z","iopub.status.idle":"2023-02-26T09:58:12.124029Z","shell.execute_reply.started":"2023-02-26T09:58:11.124779Z","shell.execute_reply":"2023-02-26T09:58:12.122773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}