{"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":"import os\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-01T12:53:19.994475Z","iopub.execute_input":"2022-08-01T12:53:19.995176Z","iopub.status.idle":"2022-08-01T12:53:20.027941Z","shell.execute_reply.started":"2022-08-01T12:53:19.995078Z","shell.execute_reply":"2022-08-01T12:53:20.02689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PATH = \"../input/rsna-2022-cervical-spine-fracture-detection\"\ntrain = pd.read_csv(os.path.join(PATH, 'train.csv'))\nmeans = train.mean(numeric_only=True).to_dict()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T12:53:20.029695Z","iopub.execute_input":"2022-08-01T12:53:20.030264Z","iopub.status.idle":"2022-08-01T12:53:20.052059Z","shell.execute_reply.started":"2022-08-01T12:53:20.030228Z","shell.execute_reply":"2022-08-01T12:53:20.050964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"means","metadata":{"execution":{"iopub.status.busy":"2022-08-01T12:53:20.054182Z","iopub.execute_input":"2022-08-01T12:53:20.055046Z","iopub.status.idle":"2022-08-01T12:53:20.064169Z","shell.execute_reply.started":"2022-08-01T12:53:20.055Z","shell.execute_reply":"2022-08-01T12:53:20.063316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dict(zip(train.columns[1:], np.average(train[train.columns[1:]], axis=0)))","metadata":{"execution":{"iopub.status.busy":"2022-08-01T12:58:15.092066Z","iopub.execute_input":"2022-08-01T12:58:15.09247Z","iopub.status.idle":"2022-08-01T12:58:15.101816Z","shell.execute_reply.started":"2022-08-01T12:58:15.092437Z","shell.execute_reply":"2022-08-01T12:58:15.10078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weighted_means = dict(zip(train.columns[1:], np.average(train[train.columns[1:]], axis=0, weights=train[\"patient_overall\"] + 1)))\nweighted_means","metadata":{"execution":{"iopub.status.busy":"2022-08-01T12:59:02.448878Z","iopub.execute_input":"2022-08-01T12:59:02.449356Z","iopub.status.idle":"2022-08-01T12:59:02.46046Z","shell.execute_reply.started":"2022-08-01T12:59:02.449304Z","shell.execute_reply":"2022-08-01T12:59:02.459354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv(os.path.join(PATH, 'test.csv'))\ntest['fractured'] = test['prediction_type'].map(weighted_means)\ntest[['row_id','fractured']].to_csv('submission.csv', index=False, float_format='%.2g')","metadata":{"execution":{"iopub.status.busy":"2022-08-01T12:59:25.39627Z","iopub.execute_input":"2022-08-01T12:59:25.397472Z","iopub.status.idle":"2022-08-01T12:59:25.412699Z","shell.execute_reply.started":"2022-08-01T12:59:25.397428Z","shell.execute_reply":"2022-08-01T12:59:25.411732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! head submission.csv","metadata":{"execution":{"iopub.status.busy":"2022-08-01T12:59:26.21201Z","iopub.execute_input":"2022-08-01T12:59:26.212405Z","iopub.status.idle":"2022-08-01T12:59:26.978287Z","shell.execute_reply.started":"2022-08-01T12:59:26.212373Z","shell.execute_reply":"2022-08-01T12:59:26.977108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}