{"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":"markdown","source":"# Solution ensemble from public notebooks","metadata":{"papermill":{"duration":0.013172,"end_time":"2021-09-22T07:34:26.661617","exception":false,"start_time":"2021-09-22T07:34:26.648445","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"\n# Solutions for blending\n\n1. https://www.kaggle.com/ammarnassanalhajali/brain-tumor-3d-blender (Score=0.73)\n1. https://www.kaggle.com/ammarnassanalhajali/brain-tumor-3d-inference (Score=0.683)\n1. https://www.kaggle.com/syerwin/efficientnet3d-with-one-mri-type (Score=0.674)\n1. https://www.kaggle.com/hijest/1-rsna-miccai-not-smart-ensemble  (Score=0.715)\n1. https://www.kaggle.com/yeeseng/miccai-shamsubmission/notebook (Score=0.677)\n\n","metadata":{"papermill":{"duration":0.012318,"end_time":"2021-09-22T07:34:26.712234","exception":false,"start_time":"2021-09-22T07:34:26.699916","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport glob\nimport os\nimport matplotlib.pyplot as plt\nimport plotly.figure_factory as ff\nimport plotly.express as px\n\nimport plotly.graph_objects as go\nfrom plotly.offline import iplot","metadata":{"papermill":{"duration":3.263001,"end_time":"2021-09-22T07:34:29.988255","exception":false,"start_time":"2021-09-22T07:34:26.725254","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:10.095163Z","iopub.execute_input":"2021-09-25T08:52:10.09582Z","iopub.status.idle":"2021-09-25T08:52:11.738829Z","shell.execute_reply.started":"2021-09-25T08:52:10.095659Z","shell.execute_reply":"2021-09-25T08:52:11.738007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_730 = pd.read_csv('../input/rsna730/730.csv')\nsub_715 = pd.read_csv('../input/brain-tumor-3d-blender-csv/RSNA_Public/715.csv')\nsub_684 = pd.read_csv('../input/brain-tumor-3d-blender-csv/RSNA_Public/684.csv')\nsub_683 = pd.read_csv('../input/brain-tumor-3d-blender-csv/RSNA_Public/683.csv')\nsub_677 = pd.read_csv('../input/braintumor3dblendercsvrsna-public677csv/677.csv')","metadata":{"papermill":{"duration":0.078095,"end_time":"2021-09-22T07:34:30.079307","exception":false,"start_time":"2021-09-22T07:34:30.001212","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:11.74066Z","iopub.execute_input":"2021-09-25T08:52:11.741138Z","iopub.status.idle":"2021-09-25T08:52:11.76788Z","shell.execute_reply.started":"2021-09-25T08:52:11.74109Z","shell.execute_reply":"2021-09-25T08:52:11.767073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_730=sub_730.sort_values(by=['BraTS21ID'], ascending=True)\nsub_730=sub_730.reset_index(drop=True)\nsub_730.head(3)","metadata":{"execution":{"iopub.status.busy":"2021-09-25T08:52:11.769256Z","iopub.execute_input":"2021-09-25T08:52:11.769709Z","iopub.status.idle":"2021-09-25T08:52:11.788343Z","shell.execute_reply.started":"2021-09-25T08:52:11.769656Z","shell.execute_reply":"2021-09-25T08:52:11.786889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_715=sub_715.sort_values(by=['BraTS21ID'], ascending=True)\nsub_715=sub_715.reset_index(drop=True)\nsub_715.head(3)","metadata":{"papermill":{"duration":0.040047,"end_time":"2021-09-22T07:34:30.1323","exception":false,"start_time":"2021-09-22T07:34:30.092253","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:11.791088Z","iopub.execute_input":"2021-09-25T08:52:11.791436Z","iopub.status.idle":"2021-09-25T08:52:11.806308Z","shell.execute_reply.started":"2021-09-25T08:52:11.791397Z","shell.execute_reply":"2021-09-25T08:52:11.805032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_684=sub_684.sort_values(by=['BraTS21ID'], ascending=True)\nsub_684=sub_684.reset_index(drop=True)\nsub_684.head(3)","metadata":{"papermill":{"duration":0.023463,"end_time":"2021-09-22T07:34:30.169162","exception":false,"start_time":"2021-09-22T07:34:30.145699","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:11.808197Z","iopub.execute_input":"2021-09-25T08:52:11.808499Z","iopub.status.idle":"2021-09-25T08:52:11.825139Z","shell.execute_reply.started":"2021-09-25T08:52:11.808466Z","shell.execute_reply":"2021-09-25T08:52:11.824247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_683=sub_683.sort_values(by=['BraTS21ID'], ascending=True)\nsub_683=sub_683.reset_index(drop=True)\nsub_683.head(3)","metadata":{"papermill":{"duration":0.028383,"end_time":"2021-09-22T07:34:30.211198","exception":false,"start_time":"2021-09-22T07:34:30.182815","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:11.826678Z","iopub.execute_input":"2021-09-25T08:52:11.827015Z","iopub.status.idle":"2021-09-25T08:52:11.846981Z","shell.execute_reply.started":"2021-09-25T08:52:11.826977Z","shell.execute_reply":"2021-09-25T08:52:11.845871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_677=sub_677.sort_values(by=['BraTS21ID'], ascending=True)\nsub_677=sub_677.reset_index(drop=True)\nsub_677.head(3)","metadata":{"execution":{"iopub.status.busy":"2021-09-25T08:52:11.848887Z","iopub.execute_input":"2021-09-25T08:52:11.849181Z","iopub.status.idle":"2021-09-25T08:52:11.863462Z","shell.execute_reply.started":"2021-09-25T08:52:11.849148Z","shell.execute_reply":"2021-09-25T08:52:11.862506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nhist_data = [sub_730.MGMT_value, sub_715.MGMT_value, sub_684.MGMT_value, sub_683.MGMT_value, sub_677.MGMT_value]\ngroup_labels = ['sub_730', 'sub_715', 'sub_684', 'sub_683', 'sub_677']\n\nfig = ff.create_distplot(hist_data, group_labels, bin_size=.2, show_hist=False, show_rug=False)\n\nfig.update_layout(\n    width = 700,\n    height = 400\n)\nfig.show()","metadata":{"papermill":{"duration":0.153437,"end_time":"2021-09-22T07:34:30.42511","exception":false,"start_time":"2021-09-22T07:34:30.271673","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:11.865205Z","iopub.execute_input":"2021-09-25T08:52:11.865761Z","iopub.status.idle":"2021-09-25T08:52:11.970313Z","shell.execute_reply.started":"2021-09-25T08:52:11.8657Z","shell.execute_reply":"2021-09-25T08:52:11.969249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# dict for the dataframes and their names\ndfs = {\"sub_730\" : sub_730, \"sub_715\" : sub_715, \"sub_684\": sub_684, \"sub_683\" : sub_683, \"sub_677\" : sub_677}\n\n# plot the data\nfig = go.Figure()\nfor i in dfs:\n    fig = fig.add_trace(go.Scatter(x = dfs[i][\"BraTS21ID\"],\n                                   y = dfs[i][\"MGMT_value\"], \n                                   mode=\"markers\",\n                                   name = i))\n    fig = fig.add_trace(\n        go.Scatter(\n            x=[0, 1010],\n            y=[0.5, 0.5],\n            mode=\"lines\",\n            line=go.scatter.Line(color=\"gray\"),\n            showlegend=False)\n    )\n\nfig.update_layout(\n    width = 700,\n    height = 500\n)\nfig.show()\n","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.046213,"end_time":"2021-09-22T07:34:30.488164","exception":false,"start_time":"2021-09-22T07:34:30.441951","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:11.972058Z","iopub.execute_input":"2021-09-25T08:52:11.972858Z","iopub.status.idle":"2021-09-25T08:52:12.00204Z","shell.execute_reply.started":"2021-09-25T08:52:11.972807Z","shell.execute_reply":"2021-09-25T08:52:12.000771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=np.corrcoef(hist_data)\nfig = px.imshow(data,x=group_labels,y=group_labels)\nfig.show()","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.844651,"end_time":"2021-09-22T07:34:31.349587","exception":false,"start_time":"2021-09-22T07:34:30.504936","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.006686Z","iopub.execute_input":"2021-09-25T08:52:12.007036Z","iopub.status.idle":"2021-09-25T08:52:12.260896Z","shell.execute_reply.started":"2021-09-25T08:52:12.007003Z","shell.execute_reply":"2021-09-25T08:52:12.2597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Finalsubmission = sub_715.copy()\nFinalsubmission['MGMT_value'] =\\\nsub_730['MGMT_value'].values*0.5\nsub_715['MGMT_value'].values*0.2 +\\\nsub_684['MGMT_value'].values*0.1+\\\nsub_683['MGMT_value'].values*0.1+\\\nsub_677['MGMT_value'].values*0.1","metadata":{"papermill":{"duration":0.029834,"end_time":"2021-09-22T07:34:31.397379","exception":false,"start_time":"2021-09-22T07:34:31.367545","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.262225Z","iopub.execute_input":"2021-09-25T08:52:12.262494Z","iopub.status.idle":"2021-09-25T08:52:12.27506Z","shell.execute_reply.started":"2021-09-25T08:52:12.262462Z","shell.execute_reply":"2021-09-25T08:52:12.273884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Finalsubmission['BraTS21ID'] = Finalsubmission['BraTS21ID'].apply(lambda x: str(x).zfill(5))","metadata":{"papermill":{"duration":0.025142,"end_time":"2021-09-22T07:34:31.439804","exception":false,"start_time":"2021-09-22T07:34:31.414662","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.276346Z","iopub.execute_input":"2021-09-25T08:52:12.276602Z","iopub.status.idle":"2021-09-25T08:52:12.290463Z","shell.execute_reply.started":"2021-09-25T08:52:12.276571Z","shell.execute_reply":"2021-09-25T08:52:12.289224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Finalsubmission.head(3)","metadata":{"papermill":{"duration":0.026702,"end_time":"2021-09-22T07:34:31.484629","exception":false,"start_time":"2021-09-22T07:34:31.457927","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.292043Z","iopub.execute_input":"2021-09-25T08:52:12.292318Z","iopub.status.idle":"2021-09-25T08:52:12.311224Z","shell.execute_reply.started":"2021-09-25T08:52:12.292274Z","shell.execute_reply":"2021-09-25T08:52:12.309995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Fsubmission = Finalsubmission.set_index('BraTS21ID')\nFsubmissionDict = Fsubmission['MGMT_value'].to_dict()","metadata":{"papermill":{"duration":0.024567,"end_time":"2021-09-22T07:34:31.526963","exception":false,"start_time":"2021-09-22T07:34:31.502396","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.313581Z","iopub.execute_input":"2021-09-25T08:52:12.314422Z","iopub.status.idle":"2021-09-25T08:52:12.325714Z","shell.execute_reply.started":"2021-09-25T08:52:12.314368Z","shell.execute_reply":"2021-09-25T08:52:12.324938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"listOfStudyPaths = glob.glob('../input/rsna-miccai-brain-tumor-radiogenomic-classification/test/*')\nlistOfStudies = [eachPath.split('/')[-1] for eachPath in listOfStudyPaths]\n\npredList = []\nfor eachStudy in listOfStudies:\n    if eachStudy not in FsubmissionDict:\n        predList.append('0.500')\n    else:\n        score = float(FsubmissionDict[eachStudy])\n        predList.append(score)\n        \nsubmission = pd.DataFrame({'BraTS21ID':listOfStudies,'MGMT_value':predList})\n","metadata":{"papermill":{"duration":0.044541,"end_time":"2021-09-22T07:34:31.588226","exception":false,"start_time":"2021-09-22T07:34:31.543685","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.326851Z","iopub.execute_input":"2021-09-25T08:52:12.327088Z","iopub.status.idle":"2021-09-25T08:52:12.345555Z","shell.execute_reply.started":"2021-09-25T08:52:12.327058Z","shell.execute_reply":"2021-09-25T08:52:12.344683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission=submission.sort_values(by=['BraTS21ID'], ascending=True)\nsubmission=submission.reset_index(drop=True)\nsubmission.head(5)","metadata":{"papermill":{"duration":0.030703,"end_time":"2021-09-22T07:34:31.636441","exception":false,"start_time":"2021-09-22T07:34:31.605738","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.346606Z","iopub.execute_input":"2021-09-25T08:52:12.34742Z","iopub.status.idle":"2021-09-25T08:52:12.368477Z","shell.execute_reply.started":"2021-09-25T08:52:12.347384Z","shell.execute_reply":"2021-09-25T08:52:12.367001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"papermill":{"duration":0.029576,"end_time":"2021-09-22T07:34:31.693239","exception":false,"start_time":"2021-09-22T07:34:31.663663","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.370667Z","iopub.execute_input":"2021-09-25T08:52:12.371483Z","iopub.status.idle":"2021-09-25T08:52:12.386459Z","shell.execute_reply.started":"2021-09-25T08:52:12.371423Z","shell.execute_reply":"2021-09-25T08:52:12.385345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 5))\nplt.hist(submission[\"MGMT_value\"]);","metadata":{"papermill":{"duration":0.217005,"end_time":"2021-09-22T07:34:31.928299","exception":false,"start_time":"2021-09-22T07:34:31.711294","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-25T08:52:12.388488Z","iopub.execute_input":"2021-09-25T08:52:12.389128Z","iopub.status.idle":"2021-09-25T08:52:12.676923Z","shell.execute_reply.started":"2021-09-25T08:52:12.389075Z","shell.execute_reply":"2021-09-25T08:52:12.675756Z"},"trusted":true},"execution_count":null,"outputs":[]}]}