{"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":247897800,"sourceType":"kernelVersion"},{"sourceId":248022342,"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-29T20:28:33.998014Z","iopub.execute_input":"2025-06-29T20:28:33.998299Z","iopub.status.idle":"2025-06-29T20:28:34.489290Z","shell.execute_reply.started":"2025-06-29T20:28:33.998269Z","shell.execute_reply":"2025-06-29T20:28:34.488449Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"indices_32_36 = [32,33,34,35,36]\nindices_37_42 = [37,38,39,41,42]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:28:34.491777Z","iopub.execute_input":"2025-06-29T20:28:34.492254Z","iopub.status.idle":"2025-06-29T20:28:34.497078Z","shell.execute_reply.started":"2025-06-29T20:28:34.492223Z","shell.execute_reply":"2025-06-29T20:28:34.496240Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_labels = pickle.load(open('/kaggle/input/gwi-preds-37-52-ds-to-notebook/val_labels.p', 'br'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:28:34.498145Z","iopub.execute_input":"2025-06-29T20:28:34.498482Z","iopub.status.idle":"2025-06-29T20:28:35.883728Z","shell.execute_reply.started":"2025-06-29T20:28:34.498454Z","shell.execute_reply":"2025-06-29T20:28:35.882584Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vals_preds = ([pickle.load(open(f'/kaggle/input/gwi-preds-32-36-ds-to-notebook/{x}/val_preds.p', 'br')) for x in indices_32_36]+\n              [pickle.load(open(f'/kaggle/input/gwi-preds-37-52-ds-to-notebook/{x}/val_preds.p', 'br')) for x in indices_37_42])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:28:35.884963Z","iopub.execute_input":"2025-06-29T20:28:35.885283Z","iopub.status.idle":"2025-06-29T20:28:48.744412Z","shell.execute_reply.started":"2025-06-29T20:28:35.885253Z","shell.execute_reply":"2025-06-29T20:28:48.743658Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vals_preds = vals_preds[::-1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:28:48.745249Z","iopub.execute_input":"2025-06-29T20:28:48.745471Z","iopub.status.idle":"2025-06-29T20:28:48.749693Z","shell.execute_reply.started":"2025-06-29T20:28:48.745453Z","shell.execute_reply":"2025-06-29T20:28:48.748893Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ensemble = np.median(vals_preds[:4], 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-29T20:29:05.709354Z","iopub.execute_input":"2025-06-29T20:29:05.709792Z","iopub.status.idle":"2025-06-29T20:29:11.220512Z","shell.execute_reply.started":"2025-06-29T20:29:05.709758Z","shell.execute_reply":"2025-06-29T20:29:11.219683Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ensemble = (vals_preds[0]*10 + vals_preds[1]*10 + vals_preds[2]*10 + vals_preds[3]*3 + vals_preds[4]*3 +\n            vals_preds[5]*2+vals_preds[6]*1+vals_preds[7]*1+vals_preds[8]*1)/(10+10+10+3+3+2+1+1+1)\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-29T20:55:13.826032Z","iopub.execute_input":"2025-06-29T20:55:13.826363Z","iopub.status.idle":"2025-06-29T20:55:14.687043Z","shell.execute_reply.started":"2025-06-29T20:55:13.826339Z","shell.execute_reply":"2025-06-29T20:55:14.686172Z"}},"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-29T20:45:05.198308Z","iopub.execute_input":"2025-06-29T20:45:05.198926Z","iopub.status.idle":"2025-06-29T20:45:05.205422Z","shell.execute_reply.started":"2025-06-29T20:45:05.198898Z","shell.execute_reply":"2025-06-29T20:45:05.204440Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-37-52-ds-to-notebook/42/val_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/41/val_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/39/val_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/38/val_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/37/val_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/36/val_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/35/val_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/34/val_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/33/val_preds.p']\nweights = [10,10,10,3,3,2,1,1,1]\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-29T20:46:23.794336Z","iopub.execute_input":"2025-06-29T20:46:23.794640Z","iopub.status.idle":"2025-06-29T20:46:26.817268Z","shell.execute_reply.started":"2025-06-29T20:46:23.794617Z","shell.execute_reply":"2025-06-29T20:46:26.816425Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pickle.dump(ensemble, open('val_ensemble.p', 'bw'))","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-37-52-ds-to-notebook/42/test_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/41/test_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/39/test_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/38/test_preds.p',\n                  '/kaggle/input/gwi-preds-37-52-ds-to-notebook/37/test_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/36/test_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/35/test_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/34/test_preds.p',\n                  '/kaggle/input/gwi-preds-32-36-ds-to-notebook/33/test_preds.p']\nweights = [10,10,10,3,3,2,1,1,1]\ntest = get_test(test_sets_path, weights)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:47:07.359184Z","iopub.execute_input":"2025-06-29T20:47:07.359498Z","iopub.status.idle":"2025-06-29T20:48:42.797068Z","shell.execute_reply.started":"2025-06-29T20:47:07.359476Z","shell.execute_reply":"2025-06-29T20:48:42.795967Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:48:42.798938Z","iopub.execute_input":"2025-06-29T20:48:42.799297Z","iopub.status.idle":"2025-06-29T20:48:42.807216Z","shell.execute_reply.started":"2025-06-29T20:48:42.799263Z","shell.execute_reply":"2025-06-29T20:48:42.806348Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(test[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:48:42.808263Z","iopub.execute_input":"2025-06-29T20:48:42.808618Z","iopub.status.idle":"2025-06-29T20:48:43.173157Z","shell.execute_reply.started":"2025-06-29T20:48:42.808597Z","shell.execute_reply":"2025-06-29T20:48:43.172243Z"}},"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-29T20:48:43.175292Z","iopub.execute_input":"2025-06-29T20:48:43.175555Z","iopub.status.idle":"2025-06-29T20:49:17.966759Z","shell.execute_reply.started":"2025-06-29T20:48:43.175527Z","shell.execute_reply":"2025-06-29T20:49:17.965958Z"}},"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-29T20:49:17.967640Z","iopub.execute_input":"2025-06-29T20:49:17.967905Z","iopub.status.idle":"2025-06-29T20:49:17.973012Z","shell.execute_reply.started":"2025-06-29T20:49:17.967885Z","shell.execute_reply":"2025-06-29T20:49:17.972002Z"}},"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-29T20:49:17.974021Z","iopub.execute_input":"2025-06-29T20:49:17.974344Z","iopub.status.idle":"2025-06-29T20:49:20.763050Z","shell.execute_reply.started":"2025-06-29T20:49:17.974317Z","shell.execute_reply":"2025-06-29T20:49:20.762082Z"}},"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-29T20:49:20.764056Z","iopub.execute_input":"2025-06-29T20:49:20.764321Z","iopub.status.idle":"2025-06-29T20:49:26.722594Z","shell.execute_reply.started":"2025-06-29T20:49:20.764302Z","shell.execute_reply":"2025-06-29T20:49:26.721504Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\nsample_submission.iloc[:, -35:] = all_preds","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-29T20:49:26.723783Z","iopub.execute_input":"2025-06-29T20:49:26.724061Z","iopub.status.idle":"2025-06-29T20:49:29.420037Z","shell.execute_reply.started":"2025-06-29T20:49:26.724033Z","shell.execute_reply":"2025-06-29T20:49:29.419072Z"}},"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-29T20:49:29.420973Z","iopub.execute_input":"2025-06-29T20:49:29.421265Z","iopub.status.idle":"2025-06-29T20:49:41.483139Z","shell.execute_reply.started":"2025-06-29T20:49:29.421238Z","shell.execute_reply":"2025-06-29T20:49:41.482269Z"}},"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-29T20:49:41.485637Z","iopub.execute_input":"2025-06-29T20:49:41.485995Z","iopub.status.idle":"2025-06-29T20:49:48.725593Z","shell.execute_reply.started":"2025-06-29T20:49:41.485965Z","shell.execute_reply":"2025-06-29T20:49:48.724735Z"}},"outputs":[],"execution_count":null}]}