{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":39763,"databundleVersionId":11756775,"sourceType":"competition"},{"sourceId":248088083,"sourceType":"kernelVersion"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport pickle\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:24.896451Z","iopub.execute_input":"2025-06-30T11:15:24.896767Z","iopub.status.idle":"2025-06-30T11:15:27.381552Z","shell.execute_reply.started":"2025-06-30T11:15:24.896734Z","shell.execute_reply":"2025-06-30T11:15:27.380548Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"indices_32_36 = [6,7,8,9,10]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:27.383357Z","iopub.execute_input":"2025-06-30T11:15:27.383874Z","iopub.status.idle":"2025-06-30T11:15:27.389087Z","shell.execute_reply.started":"2025-06-30T11:15:27.383842Z","shell.execute_reply":"2025-06-30T11:15:27.388057Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_labels = pickle.load(open('/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/val_labels.p', 'br'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:27.390075Z","iopub.execute_input":"2025-06-30T11:15:27.390336Z","iopub.status.idle":"2025-06-30T11:15:29.305374Z","shell.execute_reply.started":"2025-06-30T11:15:27.390304Z","shell.execute_reply":"2025-06-30T11:15:29.304417Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vals_preds = ([pickle.load(open(f'/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/{x}/val_preds_best.p', 'br')) for x in indices_32_36])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:29.306573Z","iopub.execute_input":"2025-06-30T11:15:29.306925Z","iopub.status.idle":"2025-06-30T11:15:35.670395Z","shell.execute_reply.started":"2025-06-30T11:15:29.306869Z","shell.execute_reply":"2025-06-30T11:15:35.669516Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vals_preds = vals_preds[::-1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:35.673069Z","iopub.execute_input":"2025-06-30T11:15:35.673354Z","iopub.status.idle":"2025-06-30T11:15:35.677781Z","shell.execute_reply.started":"2025-06-30T11:15:35.673332Z","shell.execute_reply":"2025-06-30T11:15:35.677051Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ensemble = np.median(vals_preds[:], axis = 0)\nsub_dataset_scores = []\nfor i in range(10):\n    score = np.mean(np.abs(ensemble-val_labels)[i*1000:(i+1)*1000])\n    print(score)\n    sub_dataset_scores.append(score)\nprint(np.mean(sub_dataset_scores))\nweighted_score = (np.sum(sub_dataset_scores[:4])*3+\n                  np.sum(sub_dataset_scores[4:8])*5.4+\n                  np.sum(sub_dataset_scores[8:10])*6.7)/(4*3+4*5.4+2*6.7)\nprint(weighted_score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:35.678960Z","iopub.execute_input":"2025-06-30T11:15:35.679234Z","iopub.status.idle":"2025-06-30T11:15:41.908659Z","shell.execute_reply.started":"2025-06-30T11:15:35.679212Z","shell.execute_reply":"2025-06-30T11:15:41.907612Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ensemble = (vals_preds[0]*10 + vals_preds[1]*10 + vals_preds[2]*2)/(10+10+2)\nsub_dataset_scores = []\nfor i in range(10):\n    score = np.mean(np.abs(ensemble-val_labels)[i*1000:(i+1)*1000])\n    print(score)\n    sub_dataset_scores.append(score)\nprint(np.mean(sub_dataset_scores))\nweighted_score = (np.sum(sub_dataset_scores[:4])*3+\n                  np.sum(sub_dataset_scores[4:8])*5.4+\n                  np.sum(sub_dataset_scores[8:10])*6.7)/(4*3+4*5.4+2*6.7)\nprint(weighted_score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:16:41.486579Z","iopub.execute_input":"2025-06-30T11:16:41.486924Z","iopub.status.idle":"2025-06-30T11:16:42.535415Z","shell.execute_reply.started":"2025-06-30T11:16:41.486865Z","shell.execute_reply":"2025-06-30T11:16:42.534212Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_test(test_sets_path, weights):\n    test = pickle.load(open(test_sets_path[0], 'br'))\n    \n    test = test*weights[0]\n    \n    def update_test(test, path, weight):\n        test_temp = pickle.load(open(path, 'br'))\n        test_temp = test_temp*weight\n        return test+test_temp\n        \n    for i in range(1,len(test_sets_path)):\n        test = update_test(test, test_sets_path[i], weights[i])\n    \n    test = test/np.sum(weights)\n    return test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:17:44.093141Z","iopub.execute_input":"2025-06-30T11:17:44.093456Z","iopub.status.idle":"2025-06-30T11:17:44.100155Z","shell.execute_reply.started":"2025-06-30T11:17:44.093432Z","shell.execute_reply":"2025-06-30T11:17:44.098993Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/10/val_preds_best.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/9/val_preds_best.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/8/val_preds_best.p']\nweights = [10,10,2]\n\ntest = get_test(test_sets_path, weights)\nensemble = test\n\nsub_dataset_scores = []\nfor i in range(10):\n    score = np.mean(np.abs(ensemble-val_labels)[i*1000:(i+1)*1000])\n    print(score)\n    sub_dataset_scores.append(score)\nprint(np.mean(sub_dataset_scores))\nweighted_score = (np.sum(sub_dataset_scores[:4])*3+\n                  np.sum(sub_dataset_scores[4:8])*5.4+\n                  np.sum(sub_dataset_scores[8:10])*6.7)/(4*3+4*5.4+2*6.7)\nprint(weighted_score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:17:46.307240Z","iopub.execute_input":"2025-06-30T11:17:46.307543Z","iopub.status.idle":"2025-06-30T11:17:47.938517Z","shell.execute_reply.started":"2025-06-30T11:17:46.307522Z","shell.execute_reply":"2025-06-30T11:17:47.937487Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pickle.dump(ensemble, open('val_ensemble.p', 'bw'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.919296Z","iopub.status.idle":"2025-06-30T11:15:42.919553Z","shell.execute_reply.started":"2025-06-30T11:15:42.919434Z","shell.execute_reply":"2025-06-30T11:15:42.919446Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/10/test_preds_best.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/9/test_preds_best.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/8/test_preds_best.p']\nweights = [10,10,2]\ntest = get_test(test_sets_path, weights)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.920459Z","iopub.status.idle":"2025-06-30T11:15:42.920813Z","shell.execute_reply.started":"2025-06-30T11:15:42.920619Z","shell.execute_reply":"2025-06-30T11:15:42.920636Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.922425Z","iopub.status.idle":"2025-06-30T11:15:42.922718Z","shell.execute_reply.started":"2025-06-30T11:15:42.922598Z","shell.execute_reply":"2025-06-30T11:15:42.922611Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(test[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.924088Z","iopub.status.idle":"2025-06-30T11:15:42.924361Z","shell.execute_reply.started":"2025-06-30T11:15:42.924231Z","shell.execute_reply":"2025-06-30T11:15:42.924243Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/waveform-inversion/sample_submission.csv')\nsample_submission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.925709Z","iopub.status.idle":"2025-06-30T11:15:42.926103Z","shell.execute_reply.started":"2025-06-30T11:15:42.925867Z","shell.execute_reply":"2025-06-30T11:15:42.925908Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"all_preds = np.zeros((4607260,35))\nbatch_size = 128\nx_odds = np.asarray(range(1,71,2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.926966Z","iopub.status.idle":"2025-06-30T11:15:42.927335Z","shell.execute_reply.started":"2025-06-30T11:15:42.927162Z","shell.execute_reply":"2025-06-30T11:15:42.927178Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i in range(65818//batch_size+1):\n    if i%10==0:\n        print(i)\n    preds = test[i*batch_size:(i+1)*batch_size]\n    preds = preds*100+3000\n    all_preds[i*70*batch_size:(i+1)*70*batch_size] = np.reshape(np.asarray(preds)[:, :, x_odds], [-1,35])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.928089Z","iopub.status.idle":"2025-06-30T11:15:42.928424Z","shell.execute_reply.started":"2025-06-30T11:15:42.928293Z","shell.execute_reply":"2025-06-30T11:15:42.928308Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pickle.dump(test, open('test_ensemble.p', 'bw'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.929421Z","iopub.status.idle":"2025-06-30T11:15:42.929753Z","shell.execute_reply.started":"2025-06-30T11:15:42.929595Z","shell.execute_reply":"2025-06-30T11:15:42.929611Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\nsample_submission.iloc[:, -35:] = all_preds","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.931792Z","iopub.status.idle":"2025-06-30T11:15:42.932172Z","shell.execute_reply.started":"2025-06-30T11:15:42.932019Z","shell.execute_reply":"2025-06-30T11:15:42.932037Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\nsample_submission.to_parquet('submission.parquet', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.933767Z","iopub.status.idle":"2025-06-30T11:15:42.934107Z","shell.execute_reply.started":"2025-06-30T11:15:42.933973Z","shell.execute_reply":"2025-06-30T11:15:42.933988Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.read_parquet('/kaggle/working/submission.parquet')\nplt.imshow(np.asarray(submission[:70])[:, 1:].astype(float))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T11:15:42.935423Z","iopub.status.idle":"2025-06-30T11:15:42.935669Z","shell.execute_reply.started":"2025-06-30T11:15:42.935557Z","shell.execute_reply":"2025-06-30T11:15:42.935568Z"}},"outputs":[],"execution_count":null}]}