submit2 = pd.read_csv('Christof/assets/sample_submission.csv') # custom thresholds to match lb proportions thresholds = np.linspace(0.95, 0.05, 101) pred = draw_predict_map32.copy() for j in tqdm(range(pred.shape[1])): for t in thresholds: pred[:, j] = (draw_predict_map32[:, j] > t).astype(int) prop = np.mean(pred[:, j]) if prop >= desired[j]: break print(j, '%3.2f' % t, '%6.4f' % desired[j], '%6.4f' % prop, j, ) print(pred[:5].astype(int)) label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit2['Predicted'] = str_predict_label # np.save('draw_predict_InceptionV3.npy', score_predict) submit2.to_csv(MODEL_PATH + 'submission_loss{}_lb_dist_adjusted_map32_8tta.csv'.format(exp_suffix), index=False) from Christof.utils import f1_sub sub_best = pd.read_csv('ens56d.csv') sub2 = pd.read_csv(MODEL_PATH + 'submission_loss{}_lb_dist_adjusted_8tta.csv'.format(exp_suffix)) f1_sub(sub_best,submit) f1_sub(sub_best,submit2) sub2 = pd.read_csv(MODEL_PATH + 'submission_loss{}_lb_dist_adjusted_8tta.csv'.format(exp_suffix)) f1_sub(sub_best,sub2)
j, '%3.2f' % t, '%6.4f' % desired[j], '%6.4f' % prop, j, ) print(pred[:5].astype(int)) label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit3['Predicted'] = str_predict_label # np.save('draw_predict_InceptionV3.npy', score_predict) submit3.to_csv( MODEL_PATH + 'submission_loss{}_lb_dist_adjusted_mean_loss_map32_8tta.csv'.format( exp_suffix), index=False) from Christof.utils import f1_sub sub_best = pd.read_csv('ens56d.csv') print(f1_sub(sub_best, submit)) print(f1_sub(sub_best, submit2)) print(f1_sub(sub_best, submit3)) s2 = pd.read_csv( 'Christof/models/GAPNet/13_ext/submission_loss_1_lb_dist_adjusted_8tta.csv' ) f1_sub(sub_best, s2)
for i in range(best_sub.shape[0]): for j in p0[i]: y0[i, int(j)] = 1 for i in range(28): desired[i] = y0[:,i].mean() thresholds = np.linspace(0.95, 0.05, 101) pred = preds.copy() for j in range(pred.shape[1]): for t in thresholds: pred[:, j] = (preds[:, j] > t).astype(int) prop = np.mean(pred[:, j]) if prop >= desired[j]: break print(j, '%3.2f' % t, '%6.4f' % desired[j], '%6.4f' % prop, j, ) print(pred[:5].astype(int)) label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit = pd.read_csv('Christof/assets/sample_submission.csv') submit['Predicted'] = str_predict_label # np.save('draw_predict_InceptionV3.npy', score_predict) #submit.to_csv(MODEL_PATH + 'submission.csv', index=False) from Christof.utils import f1_sub best_sub = pd.read_csv('ens56d.csv') f1_sub(best_sub,submit)
j, '%3.2f' % t, '%6.4f' % desired[j], '%6.4f' % prop, j, ) print(pred[:5].astype(int)) label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit2['Predicted'] = str_predict_label # np.save('draw_predict_InceptionV3.npy', score_predict) submit2.to_csv( MODEL_PATH + 'submission_loss{}_lb_dist_adjusted_map32_8tta.csv'.format(exp_suffix), index=False) from Christof.utils import f1_sub sub_best = pd.read_csv('ens18.csv') sub2 = pd.read_csv( MODEL_PATH + 'submission_loss{}_lb_dist_adjusted_8tta.csv'.format(exp_suffix)) f1_sub(sub_best, sub2) sub2 = pd.read_csv( MODEL_PATH + 'submission_loss{}_lb_dist_adjusted_8tta.csv'.format(exp_suffix)) f1_sub(sub_best, sub2)
print(pred[:5].astype(int)) label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit = pd.read_csv('Christof/assets/sample_submission.csv') submit['Predicted'] = str_predict_label # np.save('draw_predict_InceptionV3.npy', score_predict) submit.to_csv(MODEL_PATH + 'submission_5crop_stacked_650_freq.csv', index=False) from Christof.utils import f1_sub best_sub = pd.read_csv('ens56d.csv') f1_sub(best_sub, submit) sub_650 = pd.read_csv( 'enstw43_10en36-642_10en39b-642_10hill2-636_10-646_2.4.csv') f1_sub(sub_650, submit) gap13_ext = pd.read_csv( 'Christof/models/GAPNet/13_ext/submission_loss_5fold_mean.csv') gap13_ext_60_40 = pd.read_csv( 'Christof/models/GAPNet/13_ext_60_40/submission_loss_5fold_mean.csv') f1_sub(gap13_ext_60_40, gap13_ext) f1_sub(gap13_ext, submit) preds2 = np.load('Christof/models/GAPNet/13_ext_60_40/pred_5fold.npy')
if prop >= desired[j]: break print( j, '%3.2f' % t, '%6.4f' % desired[j], '%6.4f' % prop, j, ) print(pred[:5].astype(int)) label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit = pd.read_csv('Christof/assets/sample_submission.csv') submit['Predicted'] = str_predict_label # np.save('draw_predict_InceptionV3.npy', score_predict) submit.to_csv(MODEL_PATH + 'submission_hc.csv', index=False) from Christof.utils import f1_sub good_sub = pd.read_csv('ens56d.csv') print(f1_sub(good_sub, submit)) best_sub = pd.read_csv( 'enstw43_10en36-642_10en39b-642_10hill2-636_10-646_2.4.csv') print(f1_sub(best_sub, submit)) sub2 = pd.read_csv('Christof/hillclimb/blends/2/submission_hc.csv') print(f1_sub(best_sub, sub2))
preds[:, i] = preds[:, i] > threshs[i] from sklearn.metrics import f1_score f1_score(y0, preds, average='macro') submit = pd.read_csv('Christof/assets/sample_submission.csv') tta = 8 draw_predict = np.zeros((5, len(submit['Id']), 28)) for fold_id in range(5): draw_predict[fold_id] = np.load(MODEL_PATH + f'pred{fold_id}.npy') draw_predict1 = np.mean(draw_predict, axis=0) np.save(MODEL_PATH + f'pred_5fold_3.npy', draw_predict1) pred = draw_predict1.copy() for i in range(28): pred[:, i] = (pred[:, i] > threshs[i]).astype(int) label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit['Predicted'] = str_predict_label # np.save('draw_predict_InceptionV3.npy', score_predict) submit.to_csv(MODEL_PATH + 'submission_loss_5fold_oof_treshs.csv', index=False) from Christof.utils import f1_sub best_sub = pd.read_csv('ens56d.csv') f1_sub(best_sub, submit) old_sub = pd.read_csv(MODEL_PATH + 'submission_loss_5fold_mean.csv') f1_sub(best_sub, old_sub)
for id, prefix in enumerate(['ul','ur','mm','bl','br']): draw_predict[id] = np.load(MODEL_PATH + f'pred1_{prefix}.npy') thresholds = np.linspace(0.95, 0.05, 101) pred = draw_predict[id].copy() for j in range(pred.shape[1]): for t in thresholds: pred[:, j] = (draw_predict[id][:, j] > t).astype(int) prop = np.mean(pred[:, j]) if prop >= desired[j]: break label_predict = [np.arange(28)[score_predict == 1] for score_predict in pred] str_predict_label = [' '.join(str(l) for l in lp) for lp in label_predict] submit['Predicted'] = str_predict_label print(f1_sub(best_sub, submit)) # np.save('draw_predict_InceptionV3.npy', score_predict) submit.to_csv(MODEL_PATH + 'submission_5crop_mean.csv', index=False) #draw_predict1 = np.mean(draw_predict,axis = 0) draw_predict1 = draw_predict[0] + draw_predict[1] +1.5*draw_predict[2] +draw_predict[3]+draw_predict[4] draw_predict1 = draw_predict1 /5.5 np.save(MODEL_PATH + f'5crop_mean.npy',draw_predict1) # custom thresholds to match lb proportions thresholds = np.linspace(0.95, 0.05, 101) pred = draw_predict1.copy()