{"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-30T09:18:00.473389Z","iopub.execute_input":"2025-06-30T09:18:00.473630Z","iopub.status.idle":"2025-06-30T09:18:01.965903Z","shell.execute_reply.started":"2025-06-30T09:18:00.473586Z","shell.execute_reply":"2025-06-30T09:18:01.965044Z"}},"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-30T09:19:42.585256Z","iopub.execute_input":"2025-06-30T09:19:42.585800Z","iopub.status.idle":"2025-06-30T09:19:42.589875Z","shell.execute_reply.started":"2025-06-30T09:19:42.585775Z","shell.execute_reply":"2025-06-30T09:19:42.588979Z"}},"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-30T09:18:01.973765Z","iopub.execute_input":"2025-06-30T09:18:01.974076Z","iopub.status.idle":"2025-06-30T09:18:03.502420Z","shell.execute_reply.started":"2025-06-30T09:18:01.974047Z","shell.execute_reply":"2025-06-30T09:18:03.501467Z"}},"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.p', 'br')) for x in indices_32_36])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T09:19:44.496921Z","iopub.execute_input":"2025-06-30T09:19:44.497300Z","iopub.status.idle":"2025-06-30T09:19:51.861272Z","shell.execute_reply.started":"2025-06-30T09:19:44.497274Z","shell.execute_reply":"2025-06-30T09:19:51.860419Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vals_preds = vals_preds[::-1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T09:21:58.017935Z","iopub.execute_input":"2025-06-30T09:21:58.018319Z","iopub.status.idle":"2025-06-30T09:21:58.022792Z","shell.execute_reply.started":"2025-06-30T09:21:58.018289Z","shell.execute_reply":"2025-06-30T09:21:58.021728Z"}},"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-30T09:22:04.616725Z","iopub.execute_input":"2025-06-30T09:22:04.617004Z","iopub.status.idle":"2025-06-30T09:22:10.457000Z","shell.execute_reply.started":"2025-06-30T09:22:04.616984Z","shell.execute_reply":"2025-06-30T09:22:10.456151Z"}},"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-30T09:49:48.451763Z","iopub.execute_input":"2025-06-30T09:49:48.452070Z","iopub.status.idle":"2025-06-30T09:49:49.398985Z","shell.execute_reply.started":"2025-06-30T09:49:48.452047Z","shell.execute_reply":"2025-06-30T09:49:49.397993Z"}},"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-30T09:50:52.324388Z","iopub.execute_input":"2025-06-30T09:50:52.325223Z","iopub.status.idle":"2025-06-30T09:50:52.330640Z","shell.execute_reply.started":"2025-06-30T09:50:52.325199Z","shell.execute_reply":"2025-06-30T09:50:52.329727Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/10/val_preds.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/9/val_preds.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/8/val_preds.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-30T09:51:17.495995Z","iopub.execute_input":"2025-06-30T09:51:17.496946Z","iopub.status.idle":"2025-06-30T09:51:18.950263Z","shell.execute_reply.started":"2025-06-30T09:51:17.496908Z","shell.execute_reply":"2025-06-30T09:51:18.949560Z"}},"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-30T09:18:03.628315Z","iopub.status.idle":"2025-06-30T09:18:03.628723Z","shell.execute_reply.started":"2025-06-30T09:18:03.628522Z","shell.execute_reply":"2025-06-30T09:18:03.628538Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/10/test_preds.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/9/test_preds.p',\n                  '/kaggle/input/gwi-preds-6-10-style-ds-to-notebook/8/test_preds.p']\nweights = [10,10,2]\ntest = get_test(test_sets_path, weights)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T09:18:03.629735Z","iopub.status.idle":"2025-06-30T09:18:03.630079Z","shell.execute_reply.started":"2025-06-30T09:18:03.629905Z","shell.execute_reply":"2025-06-30T09:18:03.629922Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T09:18:03.699688Z","iopub.status.idle":"2025-06-30T09:18:03.700103Z","shell.execute_reply.started":"2025-06-30T09:18:03.699912Z","shell.execute_reply":"2025-06-30T09:18:03.699930Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(test[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T09:18:03.702113Z","iopub.status.idle":"2025-06-30T09:18:03.702400Z","shell.execute_reply.started":"2025-06-30T09:18:03.702273Z","shell.execute_reply":"2025-06-30T09:18:03.702285Z"}},"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-30T09:18:03.703271Z","iopub.status.idle":"2025-06-30T09:18:03.703630Z","shell.execute_reply.started":"2025-06-30T09:18:03.703416Z","shell.execute_reply":"2025-06-30T09:18:03.703432Z"}},"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-30T09:18:03.704622Z","iopub.status.idle":"2025-06-30T09:18:03.705035Z","shell.execute_reply.started":"2025-06-30T09:18:03.704861Z","shell.execute_reply":"2025-06-30T09:18:03.704878Z"}},"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-30T09:18:03.706097Z","iopub.status.idle":"2025-06-30T09:18:03.706387Z","shell.execute_reply.started":"2025-06-30T09:18:03.706261Z","shell.execute_reply":"2025-06-30T09:18:03.706278Z"}},"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-30T09:18:03.707021Z","iopub.status.idle":"2025-06-30T09:18:03.707270Z","shell.execute_reply.started":"2025-06-30T09:18:03.707149Z","shell.execute_reply":"2025-06-30T09:18:03.707161Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\nsample_submission.iloc[:, -35:] = all_preds","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T09:18:03.708796Z","iopub.status.idle":"2025-06-30T09:18:03.709068Z","shell.execute_reply.started":"2025-06-30T09:18:03.708937Z","shell.execute_reply":"2025-06-30T09:18:03.708952Z"}},"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-30T09:18:03.710743Z","iopub.status.idle":"2025-06-30T09:18:03.711086Z","shell.execute_reply.started":"2025-06-30T09:18:03.710913Z","shell.execute_reply":"2025-06-30T09:18:03.710929Z"}},"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-30T09:18:03.712712Z","iopub.status.idle":"2025-06-30T09:18:03.713052Z","shell.execute_reply.started":"2025-06-30T09:18:03.712881Z","shell.execute_reply":"2025-06-30T09:18:03.712897Z"}},"outputs":[],"execution_count":null}]}