{"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":10384,"databundleVersionId":120379,"sourceType":"competition"},{"sourceId":11947744,"sourceType":"datasetVersion","datasetId":7511235},{"sourceId":11948286,"sourceType":"datasetVersion","datasetId":7511615}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport glob\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-25T16:21:31.767378Z","iopub.execute_input":"2025-05-25T16:21:31.767798Z","iopub.status.idle":"2025-05-25T16:21:31.772368Z","shell.execute_reply.started":"2025-05-25T16:21:31.767694Z","shell.execute_reply":"2025-05-25T16:21:31.771446Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Get all the prediction CSVs from the folder where we uploaded it\npreds_dir = \"/kaggle/input/d/iraj09/plaastic-test-predictions-full/preds\"\ncsv_files = glob.glob(os.path.join(preds_dir, \"*.csv\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T16:22:03.931287Z","iopub.execute_input":"2025-05-25T16:22:03.931798Z","iopub.status.idle":"2025-05-25T16:22:03.950097Z","shell.execute_reply.started":"2025-05-25T16:22:03.931765Z","shell.execute_reply":"2025-05-25T16:22:03.948492Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Did the processing in batches so need to concatenate them back together\nall_results = []\n\nfor file in csv_files:\n    df = pd.read_csv(file)\n    df.columns = ['object_id', 'predicted_class']\n    \n    df_onehot = pd.get_dummies(df['predicted_class'], prefix='class')\n    result = pd.concat([df['object_id'], df_onehot], axis=1)\n    result = result.groupby('object_id').sum().reset_index()\n    \n    all_results.append(result)\n\n# Aforementioned concatenation\nif all_results:\n    final_df = pd.concat(all_results, ignore_index=True)\n\n     # Need class_99 to be present even tho we didn't predict, gotta match sample\n    if 'class_99' not in final_df.columns:\n        final_df['class_99'] = 0  # Add column with 0s\n\n    # Sorting by object_id to match the sample submission structure\n    final_df = final_df.sort_values(by='object_id').reset_index(drop=True)\n\n    # Print class-wise prediction counts\n    class_totals = final_df.drop(columns=['object_id']).sum().astype(int)\n    print(\"📊 Class prediction counts:\")\n    print(class_totals)\n\n    # Quick preview of the thingy\n    print(\"\\n🧾 Preview of final predictions:\")\n    print(final_df.head())\nelse:\n    print(\"⚠️ No CSV files !\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T16:22:07.321131Z","iopub.execute_input":"2025-05-25T16:22:07.321447Z","iopub.status.idle":"2025-05-25T16:22:15.038525Z","shell.execute_reply.started":"2025-05-25T16:22:07.321410Z","shell.execute_reply":"2025-05-25T16:22:15.037608Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Save final result to CSV for the submission !\nprint(\"💾  Saving...\")\nfinal_df.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T16:22:24.099267Z","iopub.execute_input":"2025-05-25T16:22:24.099574Z","iopub.status.idle":"2025-05-25T16:22:37.448218Z","shell.execute_reply.started":"2025-05-25T16:22:24.099550Z","shell.execute_reply":"2025-05-25T16:22:37.447098Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Print the whole final thingy\nprint(final_df)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T16:22:41.590527Z","iopub.execute_input":"2025-05-25T16:22:41.590909Z","iopub.status.idle":"2025-05-25T16:22:41.601702Z","shell.execute_reply.started":"2025-05-25T16:22:41.590878Z","shell.execute_reply":"2025-05-25T16:22:41.600538Z"}},"outputs":[],"execution_count":null}]}