{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Abstract\nI've been doing LB probe, and I will report all of them because probably completed.  "},{"metadata":{"trusted":true},"cell_type":"code","source":"import collections\nimport math\nimport os\nimport pathlib\nimport platform\nimport sys\nimport warnings\n\nimport numpy as np\nimport numpy as np\nimport pandas as pd\nimport pandas as pd\nimport sklearn.metrics\nimport sympy\n\nfrom joblib import Parallel, delayed\nfrom tqdm import tqdm\n\n\n# Filter warnings\nwarnings.simplefilter(action='ignore', category=FutureWarning)\nwarnings.filterwarnings('ignore')\n\n# Get working directory\ntry:\n    path_working_dir = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))\nexcept:\n    path_working_dir = os.path.abspath(str(pathlib.Path().resolve()))\n\n# Set input directory, and make output directory\nlist_nodename = ['.local', 'CM-1080Ti']\nif max([platform.node().find(nodename) for nodename in list_nodename]) > -1:\n    path_input  = os.path.abspath(os.path.join(path_working_dir, '../../../input/rsna-intracranial-hemorrhage-detection'))\n    path_output = path_working_dir.replace('/src/', '/output/')\n    os.makedirs(path_output, exist_ok=True)\nelse: # maybe kaggle kernel\n    path_input  = '../input/rsna-intracranial-hemorrhage-detection'\n    path_output = './'\nassert os.path.exists(path_input) == True\n\n# Load sample_submission.csv, set labels are 0.5 in case overwrited\ndf_submission          = pd.read_csv(os.path.join(path_input, 'stage_1_sample_submission.csv'))\ndf_submission          = pd.read_csv(os.path.join(path_input, 'stage_1_sample_submission.csv'))\ndf_submission['Label'] = 0.5","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Reveal weights\n\n> Submissions are evaluated using a weighted multi-label logarithmic loss. Each hemorrhage sub-type is its own row for every image, and you are expected to predict a probability for that sub-type of hemorrhage. There is also an any label, which indicates that a hemorrhage of ANY kind exists in the image. Theany label is weighted more highly than specific hemorrhage sub-types.\n> \n> For each image Id, you must submit a set of predicted probabilities (a separate row for each sub-type). We then take the log loss for each predicted probability versus its true label. Finally, loss is averaged across all samples.\n> \n> In order to avoid the extremes of the log function, predicted probabilities are replaced with max(min(p,1−10−15),10−15).\n>\n> by https://www.kaggle.com/c/rsna-intracranial-hemorrhage-detection/overview/evaluation\n\nThe evaluation function is explained above, but the weight is not clear.  \nI used the following two points to estimate weights using simultaneous equations.\n\n* The logloss should be the same regardless of the answer when the predicted value is 0.5 all.  \n* The submission score depends on the weight and the number of positive samples when a particular class's all predicted values are same.  \n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# Reduced the number of digits and made it the same as LB for easy calculation\n# Define logloss, using LB digits(XX.XXX)\nlogloss      = {}\nlogloss[0.5] = -math.log(0.5)           * 1000 * 1000 // 1000 / 1000 #  0.693\nlogloss[0]   = -math.log(1 - 10**(-15)) * 1000 * 1000 // 1000 / 1000 #  0.000\nlogloss[1]   = -math.log(    10**(-15)) * 1000 * 1000 // 1000 / 1000 # 34.538","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"# Define Variables, weights are 0-1(relative value), positives are 0-78545(N of stage 1 test images)\nweights_epidural           = sympy.Symbol('weights_epidural')\nweights_intraparenchymal   = sympy.Symbol('weights_intraparenchymal')\nweights_intraventricular   = sympy.Symbol('weights_intraventricular')\nweights_subarachnoid       = sympy.Symbol('weights_subarachnoid')\nweights_subdural           = sympy.Symbol('weights_subdural')\nweights_any                = sympy.Symbol('weights_any')\npositives_epidural         = sympy.Symbol('positives_epidural')\npositives_intraparenchymal = sympy.Symbol('positives_intraparenchymal')\npositives_intraventricular = sympy.Symbol('positives_intraventricular')\npositives_subarachnoid     = sympy.Symbol('positives_subarachnoid')\npositives_subdural         = sympy.Symbol('positives_subdural')\npositives_any              = sympy.Symbol('positives_any')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Create submission_file, df_any_{0, 1} means *_any's label is {0, 1} else labels are 0.5\ndf_epidural_0               = df_submission.copy()\ndf_epidural_0.iloc[0::6, 1] = 0\ndf_epidural_0.to_csv(os.path.join(path_output, 'submission_epidural_0.csv'), index=False)\n\ndf_epidural_1               = df_submission.copy()\ndf_epidural_1.iloc[0::6, 1] = 1\ndf_epidural_1.to_csv(os.path.join(path_output, 'submission_epidural_1.csv'), index=False)\n\ndf_intraparenchymal_0               = df_submission.copy()\ndf_intraparenchymal_0.iloc[1::6, 1] = 0\ndf_intraparenchymal_0.to_csv(os.path.join(path_output, 'submission_intraparenchymal_0.csv'), index=False)\n\ndf_intraparenchymal_1               = df_submission.copy()\ndf_intraparenchymal_1.iloc[1::6, 1] = 1\ndf_intraparenchymal_1.to_csv(os.path.join(path_output, 'submission_intraparenchymal_1.csv'), index=False)\n\ndf_intraventricular_0               = df_submission.copy()\ndf_intraventricular_0.iloc[2::6, 1] = 0\ndf_intraventricular_0.to_csv(os.path.join(path_output, 'submission_intraventricular_0.csv'), index=False)\n\ndf_intraventricular_1               = df_submission.copy()\ndf_intraventricular_1.iloc[2::6, 1] = 1\ndf_intraventricular_1.to_csv(os.path.join(path_output, 'submission_intraventricular_1.csv'), index=False)\n\ndf_subarachnoid_0               = df_submission.copy()\ndf_subarachnoid_0.iloc[3::6, 1] = 0\ndf_subarachnoid_0.to_csv(os.path.join(path_output, 'submission_subarachnoid_0.csv'), index=False)\n\ndf_subarachnoid_1               = df_submission.copy()\ndf_subarachnoid_1.iloc[3::6, 1] = 1\ndf_subarachnoid_1.to_csv(os.path.join(path_output, 'submission_subarachnoid_1.csv'), index=False)\n\ndf_subdural_0               = df_submission.copy()\ndf_subdural_0.iloc[4::6, 1] = 0\ndf_subdural_0.to_csv(os.path.join(path_output, 'submission_subdural_0.csv'), index=False)\n\ndf_subdural_1               = df_submission.copy()\ndf_subdural_1.iloc[4::6, 1] = 1\ndf_subdural_1.to_csv(os.path.join(path_output, 'submission_subdural_1.csv'), index=False)\n\ndf_any_0               = df_submission.copy()\ndf_any_0.iloc[5::6, 1] = 0\ndf_any_0.to_csv(os.path.join(path_output, 'submission_any_0.csv'), index=False)\n\ndf_any_1               = df_submission.copy()\ndf_any_1.iloc[5::6, 1] = 1\ndf_any_1.to_csv(os.path.join(path_output, 'submission_any_1.csv'), index=False)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Submit everyday..."},{"metadata":{"trusted":true},"cell_type":"code","source":"# Input LB socre: submission_{epidural, intraparenchymal, intraventricular, subarachnoid, subdural, any}_{0, 1}.csv, 'lb_score_* = - XX.XXX + ...' is LB SCORE\nlb_score_epidural_0 = - 0.618 + ((1 - weights_epidural) * logloss[0.5]) + (weights_epidural * (sympy.Symbol('positives_epidural') * logloss[1] + (78545 - sympy.Symbol('positives_epidural')) * logloss[0]) / 78545)\nlb_score_epidural_1 = - 5.504 + ((1 - weights_epidural) * logloss[0.5]) + (weights_epidural * (sympy.Symbol('positives_epidural') * logloss[0] + (78545 - sympy.Symbol('positives_epidural')) * logloss[1]) / 78545)\n\nlb_score_intraparenchymal_0 = - 0.817 + ((1 - weights_intraparenchymal) * logloss[0.5]) + (weights_intraparenchymal * (sympy.Symbol('positives_intraparenchymal') * logloss[1] + (78545 - sympy.Symbol('positives_intraparenchymal')) * logloss[0]) / 78545)\nlb_score_intraparenchymal_1 = - 5.305 + ((1 - weights_intraparenchymal) * logloss[0.5]) + (weights_intraparenchymal * (sympy.Symbol('positives_intraparenchymal') * logloss[0] + (78545 - sympy.Symbol('positives_intraparenchymal')) * logloss[1]) / 78545)\n\nlb_score_intraventricular_0 = - 0.747 + ((1 - weights_intraventricular) * logloss[0.5]) + (weights_intraventricular * (sympy.Symbol('positives_intraventricular') * logloss[1] + (78545 - sympy.Symbol('positives_intraventricular')) * logloss[0]) / 78545)\nlb_score_intraventricular_1 = - 5.375 + ((1 - weights_intraventricular) * logloss[0.5]) + (weights_intraventricular * (sympy.Symbol('positives_intraventricular') * logloss[0] + (78545 - sympy.Symbol('positives_intraventricular')) * logloss[1]) / 78545)\n\nlb_score_subarachnoid_0 = - 0.817 + ((1 - weights_subarachnoid) * logloss[0.5]) + (weights_subarachnoid * (sympy.Symbol('positives_subarachnoid') * logloss[1] + (78545 - sympy.Symbol('positives_subarachnoid')) * logloss[0]) / 78545)\nlb_score_subarachnoid_1 = - 5.305 + ((1 - weights_subarachnoid) * logloss[0.5]) + (weights_subarachnoid * (sympy.Symbol('positives_subarachnoid') * logloss[0] + (78545 - sympy.Symbol('positives_subarachnoid')) * logloss[1]) / 78545)\n\nlb_score_subdural_0 = - 0.887 + ((1 - weights_subdural) * logloss[0.5]) + (weights_subdural * (sympy.Symbol('positives_subdural') * logloss[1] + (78545 - sympy.Symbol('positives_subdural')) * logloss[0]) / 78545)\nlb_score_subdural_1 = - 5.234 + ((1 - weights_subdural) * logloss[0.5]) + (weights_subdural * (sympy.Symbol('positives_subdural') * logloss[0] + (78545 - sympy.Symbol('positives_subdural')) * logloss[1]) / 78545)\n\nlb_score_any_0 = - 1.855 + ((1 - weights_any) * logloss[0.5]) + (weights_any * (sympy.Symbol('positives_any') * logloss[1] + (78545 - sympy.Symbol('positives_any')) * logloss[0]) / 78545)\nlb_score_any_1 = - 9.002 + ((1 - weights_any) * logloss[0.5]) + (weights_any * (sympy.Symbol('positives_any') * logloss[0] + (78545 - sympy.Symbol('positives_any')) * logloss[1]) / 78545)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Solve {weights, positives}_epidural\nsolution = []\nsolution.append(sympy.solve([lb_score_epidural_0,         lb_score_epidural_1        ])[0].values())\nsolution.append(sympy.solve([lb_score_intraparenchymal_0, lb_score_intraparenchymal_1])[0].values())\nsolution.append(sympy.solve([lb_score_intraventricular_0, lb_score_intraventricular_1])[0].values())\nsolution.append(sympy.solve([lb_score_subarachnoid_0,     lb_score_subarachnoid_1    ])[0].values())\nsolution.append(sympy.solve([lb_score_subdural_0,         lb_score_subdural_1        ])[0].values())\nsolution.append(sympy.solve([lb_score_any_0,              lb_score_any_1             ])[0].values())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Output results, 0.1428 ≒ 1 / 7, 7 = 5 + 1 * 2, so I think *_any weight is x2 of others\ndf_output = pd.DataFrame(solution, columns=['N_positives', 'weight'], index=['epidural', 'intraparenchymal', 'intraventricular', 'subarachnoid', 'subdural', 'any'])\ndf_output","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**The weights are probably 1/7 and 2/7.**  \n**In other words, they are 1 : 1 : 1 : 1 : 1: 2, any's weight is x2 of others.**  \n\nThere is a problem with effective digits and the number of positive samples is actually wrong."},{"metadata":{},"cell_type":"markdown","source":"# Reveal number of positive samples and scoring metrics\n\nIt took a lot of time to realize that the number of digits in LB was not rounded.  \nI was helped by other competition discussions.  \n\n* https://www.kaggle.com/c/porto-seguro-safe-driver-prediction/discussion/41237\n* https://www.kaggle.com/c/carvana-image-masking-challenge/discussion/38301\n\nAnd, at first I used my implementation function(includes bugs?) for scoring.  \nI read evaluation page over and over again, and realized that the divergence prevention process is identical to the logloss function of scikit-learn.  \nAlso, Instant Gratification competition uses scikit-learn to generate the dataset, I thought scitkit-learn is definitely used for score calculation."},{"metadata":{"trusted":true},"cell_type":"code","source":"# Fianly my scoring function\n\n# LB ceiling digits\ndef ceil(x, digits=0):\n    return float(str(x)[:str(x).find('.') + 1 + digits])\n\n# scikit-learn scoring\n# sklearn.metrics.log_loss(y_true, y_pred, sample_weights=[1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, ...])\n# CAUTION: the function below is for LB probe\ndef get_score_v5(n_positives, pred_all, weight):\n    if weight == 1:\n        return ceil(sklearn.metrics.log_loss(y_true=([0] * (78545 * 6 - n_positives) + [1] * n_positives), y_pred=([0.5] * 78545 * 5 + [pred_all] * 78545), labels=[0, 1], sample_weight=[2] * 78545 + [1] * 78545 * 5), 3)\n    elif weight == 2:\n        return ceil(sklearn.metrics.log_loss(y_true=([0] * (78545 * 6 - n_positives) + [1] * n_positives), y_pred=([0.5] * 78545 * 5 + [pred_all] * 78545), labels=[0, 1], sample_weight=[1] * 78545 * 5 + [2] * 78545), 3)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The score function is slow, so search around the known N_positives with low precisionthe when reveal weights."},{"metadata":{"trusted":true},"cell_type":"code","source":"list_n_positives_epidural = list(range(int(df_output['N_positives']['epidural']) - 25, int(df_output['N_positives']['epidural']) + 25))\n\nlist_n_positives_epidural = [n_positives for n_positives in list_n_positives_epidural if 0.618 == get_score_v5(n_positives, pred_all=0,      weight=1)]\nlist_n_positives_epidural = [n_positives for n_positives in list_n_positives_epidural if 5.504 == get_score_v5(n_positives, pred_all=1,      weight=1)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"list_n_positives_epidural","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"As described below, find pred_all like bellow that can distinguish the above N_positives by LB score.  \nThe creation of the submission file is omitted as similar code is described above.  "},{"metadata":{"trusted":true},"cell_type":"code","source":"comment_out = '''\nfor i in tqdm(range(1, 10000)):\n    pred_all      = i / 10000\n    list_lb_score = [get_score_v5(n_positives, pred_all=pred_all, weight=1) for n_positives in list_n_positives_epidural]\n    counter       = collections.Counter(list_lb_score)\n    counter_left  = []\n    if len(set(list_lb_score)) != 1:\n        print(pred_all, list_lb_score, counter)\n        counter_left.append(min([items[1] for items in counter.items()]))\n        if len(set(counter_left)) == len(list_n_positives_epidural):\n            break\n'''\nsample_output_subarachnoid = '''\n  2%|▏         | 232/9999 [07:44<5:15:49,  1.94s/it]\n0.0028 [0.632, 0.632, 0.632, 0.632, 0.632, 0.632, 0.632, 0.632, 0.633] Counter({0.632: 8, 0.633: 1})\n0.0046 [0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.63] Counter({0.629: 8, 0.63: 1})\n0.0054 [0.628, 0.628, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629] Counter({0.629: 7, 0.628: 2})\n0.0077 [0.626, 0.626, 0.627, 0.627, 0.627, 0.627, 0.627, 0.627, 0.627] Counter({0.627: 7, 0.626: 2})\n0.0093 [0.625, 0.625, 0.625, 0.625, 0.626, 0.626, 0.626, 0.626, 0.626] Counter({0.626: 5, 0.625: 4})\n0.0113 [0.624, 0.624, 0.624, 0.624, 0.625, 0.625, 0.625, 0.625, 0.625] Counter({0.625: 5, 0.624: 4})\n0.0139 [0.623, 0.623, 0.623, 0.624, 0.624, 0.624, 0.624, 0.624, 0.624] Counter({0.624: 6, 0.623: 3})\n0.014 [0.623, 0.623, 0.623, 0.623, 0.623, 0.623, 0.623, 0.623, 0.624] Counter({0.623: 8, 0.624: 1})\n0.0174 [0.622, 0.623, 0.623, 0.623, 0.623, 0.623, 0.623, 0.623, 0.623] Counter({0.623: 8, 0.622: 1})\n0.0175 [0.622, 0.622, 0.622, 0.622, 0.622, 0.623, 0.623, 0.623, 0.623] Counter({0.622: 5, 0.623: 4})\n0.0176 [0.622, 0.622, 0.622, 0.622, 0.622, 0.622, 0.622, 0.622, 0.623] Counter({0.622: 8, 0.623: 1})\n0.0227 [0.621, 0.622, 0.622, 0.622, 0.622, 0.622, 0.622, 0.622, 0.622] Counter({0.622: 8, 0.621: 1})\n0.0228 [0.621, 0.621, 0.621, 0.621, 0.622, 0.622, 0.622, 0.622, 0.622] Counter({0.622: 5, 0.621: 4})\n0.0229 [0.621, 0.621, 0.621, 0.621, 0.621, 0.621, 0.622, 0.622, 0.622] Counter({0.621: 6, 0.622: 3})\n0.023 [0.621, 0.621, 0.621, 0.621, 0.621, 0.621, 0.621, 0.621, 0.622] Counter({0.621: 8, 0.622: 1})\n'''","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"list_n_positives_epidural = [n_positives for n_positives in list_n_positives_epidural if 0.853 == get_score_v5(n_positives, pred_all=0.838,  weight=1)]\nlist_n_positives_epidural = [n_positives for n_positives in list_n_positives_epidural if 1.181 == get_score_v5(n_positives, pred_all=0.984,  weight=1)]\nlist_n_positives_epidural = [n_positives for n_positives in list_n_positives_epidural if 0.599 == get_score_v5(n_positives, pred_all=0.0128, weight=1)]\n\nlist_n_positives_epidural","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Yeah, I found `n_positives_epidural == 384`!!!!**"},{"metadata":{"trusted":true},"cell_type":"code","source":"list_n_positives_intraparenchymal = list(range(int(df_output['N_positives']['intraparenchymal']) - 25, int(df_output['N_positives']['intraparenchymal']) + 25))\n\nlist_n_positives_intraparenchymal = [n_positives for n_positives in list_n_positives_intraparenchymal if 0.817 == get_score_v5(n_positives, pred_all=0,      weight=1)]\nlist_n_positives_intraparenchymal = [n_positives for n_positives in list_n_positives_intraparenchymal if 5.305 == get_score_v5(n_positives, pred_all=1,      weight=1)]\nlist_n_positives_intraparenchymal = [n_positives for n_positives in list_n_positives_intraparenchymal if 0.625 == get_score_v5(n_positives, pred_all=0.0105, weight=1)]\nlist_n_positives_intraparenchymal = [n_positives for n_positives in list_n_positives_intraparenchymal if 0.627 == get_score_v5(n_positives, pred_all=0.0072, weight=1)]\nlist_n_positives_intraparenchymal = [n_positives for n_positives in list_n_positives_intraparenchymal if 0.622 == get_score_v5(n_positives, pred_all=0.0955, weight=1)]\n\nlist_n_positives_intraparenchymal","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"list_n_positives_intraventricular = list(range(int(df_output['N_positives']['intraventricular']) - 25, int(df_output['N_positives']['intraventricular']) + 25))\n\nlist_n_positives_intraventricular = [n_positives for n_positives in list_n_positives_intraventricular if 0.747 == get_score_v5(n_positives, pred_all=0,      weight=1)]\nlist_n_positives_intraventricular = [n_positives for n_positives in list_n_positives_intraventricular if 5.375 == get_score_v5(n_positives, pred_all=1,      weight=1)]\nlist_n_positives_intraventricular = [n_positives for n_positives in list_n_positives_intraventricular if 0.614 == get_score_v5(n_positives, pred_all=0.0245, weight=1)]\nlist_n_positives_intraventricular = [n_positives for n_positives in list_n_positives_intraventricular if 0.613 == get_score_v5(n_positives, pred_all=0.0249, weight=1)]\nlist_n_positives_intraventricular = [n_positives for n_positives in list_n_positives_intraventricular if 0.616 == get_score_v5(n_positives, pred_all=0.0098, weight=1)]\n\nlist_n_positives_intraventricular","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"list_n_positives_subarachnoid = list(range(int(df_output['N_positives']['subarachnoid']) - 25, int(df_output['N_positives']['subarachnoid']) + 25))\n\nlist_n_positives_subarachnoid = [n_positives for n_positives in list_n_positives_subarachnoid if 0.817 == get_score_v5(n_positives, pred_all=0,      weight=1)]\nlist_n_positives_subarachnoid = [n_positives for n_positives in list_n_positives_subarachnoid if 5.305 == get_score_v5(n_positives, pred_all=1,      weight=1)]\nlist_n_positives_subarachnoid = [n_positives for n_positives in list_n_positives_subarachnoid if 0.625 == get_score_v5(n_positives, pred_all=0.0105, weight=1)]\nlist_n_positives_subarachnoid = [n_positives for n_positives in list_n_positives_subarachnoid if 0.626 == get_score_v5(n_positives, pred_all=0.0072, weight=1)]\nlist_n_positives_subarachnoid = [n_positives for n_positives in list_n_positives_subarachnoid if 0.628 == get_score_v5(n_positives, pred_all=0.0060, weight=1)]\n\nlist_n_positives_subarachnoid","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"list_n_positives_subdural = list(range(int(df_output['N_positives']['subdural']) - 25, int(df_output['N_positives']['subdural']) + 25))\n\nlist_n_positives_subdural = [n_positives for n_positives in list_n_positives_subdural if 0.887 == get_score_v5(n_positives, pred_all=0,      weight=1)]\nlist_n_positives_subdural = [n_positives for n_positives in list_n_positives_subdural if 5.234 == get_score_v5(n_positives, pred_all=1,      weight=1)]\nlist_n_positives_subdural = [n_positives for n_positives in list_n_positives_subdural if 0.634 == get_score_v5(n_positives, pred_all=0.0095, weight=1)]\nlist_n_positives_subdural = [n_positives for n_positives in list_n_positives_subdural if 0.641 == get_score_v5(n_positives, pred_all=0.0038, weight=1)]\nlist_n_positives_subdural = [n_positives for n_positives in list_n_positives_subdural if 0.640 == get_score_v5(n_positives, pred_all=0.0043, weight=1)]\nlist_n_positives_subdural = [n_positives for n_positives in list_n_positives_subdural if 0.626 == get_score_v5(n_positives, pred_all=0.0394, weight=1)]\n\nlist_n_positives_subdural","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# CAUTION: weight = 2\nlist_n_positives_any = list(range(int(df_output['N_positives']['any']) - 25, int(df_output['N_positives']['any']) + 25))\n\nlist_n_positives_any = [n_positives for n_positives in list_n_positives_any if 1.855 == get_score_v5(n_positives, pred_all=0,     weight=2)]\nlist_n_positives_any = [n_positives for n_positives in list_n_positives_any if 9.002 == get_score_v5(n_positives, pred_all=1,     weight=2)]\nlist_n_positives_any = [n_positives for n_positives in list_n_positives_any if 0.628 == get_score_v5(n_positives, pred_all=0.046, weight=2)]\nlist_n_positives_any = [n_positives for n_positives in list_n_positives_any if 0.621 == get_score_v5(n_positives, pred_all=0.058, weight=2)]\n\nlist_n_positives_any","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## **I summarize the results!!**\n\n* weights: any is x2 of others\n* n_positives: following table\n* scoring: `sklearn.metrics.log_loss()`, with `sample_weight=([1, 1, 1, 1, 1, 2] * 78545)`"},{"metadata":{"trusted":true},"cell_type":"code","source":"# Load train labels\ndf_input_train_stage_1 = pd.read_csv(os.path.join(path_input, 'stage_1_train.csv'))\n\n\n# Output summary\ndf_input_train_stage_1 = pd.read_csv(os.path.join(path_input, 'stage_1_train.csv'))\nlist_n_positives_train = [df_input_train_stage_1['Label'][i::6].sum() for i in range(6)]\nlist_n_positives_test  = [list_n_positives_epidural[0], list_n_positives_intraparenchymal[0], list_n_positives_intraventricular[0], list_n_positives_subarachnoid[0], list_n_positives_subdural[0], list_n_positives_any[0]]\ndf_summary                       = pd.DataFrame([list_n_positives_train, list_n_positives_test], columns=['epidural', 'intraparenchymal', 'intraventricular', 'subarachnoid', 'subdural', 'any'], index=['N_positives_train', 'N_positives_test']).T\ndf_summary['ratio_N_positives_train'] = df_summary['N_positives_train'] / (len(df_input_train_stage_1) / 6)\ndf_summary['ratio_N_positives_test']  = df_summary['N_positives_test']  / (len(df_submission) / 6)\ndf_summary['weight']             = [1, 1, 1, 1, 1, 2]\ndf_summary","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Thank you for your reading, and let's enjoy the competition together!!\n\nFinally, I'll start submitting model's predictions and developing ML pipelines:)"}],"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":4,"nbformat_minor":1}