pred = deepcopy(pred_val) # if predicted proba >= 0.5, this label is set to 1. if all probas < 0.5, the label with largest proba is set to 1 for i in range(pred.shape[0]): if len(np.where(pred[i] >= th)[0]) > 0: pred[i][pred[i] >= th] = 1 pred[i][pred[i] < th] = 0 else: max_index = np.argmax(pred[i]) pred[i] = 0 pred[i][max_index] = 1 # In[ ]: acc_val = hamming_score(y_val_issue_single, pred) p_val, r_val, f1_val = f1(y_val_issue_single, pred) # acc_val = hamming_score(y_val_reshape, pred) # p_val, r_val, f1_val = f1(y_val_reshape, pred) # p_S = precision_S(y_valid_multi_reshape, pred) # r_S = recall_S(y_valid_multi_reshape, pred) # f1_S = (2 * p_S * r_S)/(p_S + r_S) print('Eval====>Th: {}, Acc: {}, P: {}, R: {}, F1: {}'.format( th, acc_val, p_val, r_val, f1_val)) # print('Eval====>Th: {}, P_S: {}, R_S: {}, F1_S: {}'.format(th, p_S, r_S, f1_S)) # In[ ]: pred = deepcopy(pred_test)
for th in [0.2, 0.3, 0.4, 0.5, 0.6, 0.7]: pred = deepcopy(pred_val) # if predicted proba >= 0.5, this label is set to 1. if all probas < 0.5, the label with largest proba is set to 1 for i in range(pred.shape[0]): if len(np.where(pred[i] >= th)[0]) > 0: pred[i][pred[i] >= th] = 1 pred[i][pred[i] < th] = 0 else: max_index = np.argmax(pred[i]) pred[i] = 0 pred[i][max_index] = 1 # In[ ]: acc_val = hamming_score(y_val_reshape, pred) p_val, r_val, f1_val = f1(y_val_reshape, pred) print('Eval====>Th: {}, Acc: {}, P: {}, R: {}, F1: {}'.format(th, acc_val, p_val, r_val, f1_val)) # In[ ]: pred = deepcopy(pred_test) for i in range(pred.shape[0]): if len(np.where(pred[i] >= th)[0]) > 0: pred[i][pred[i] >= th] = 1 pred[i][pred[i] < th] = 0 else: max_index = np.argmax(pred[i]) pred[i] = 0 pred[i][max_index] = 1
for th in [0.2, 0.3, 0.4, 0.5, 0.6, 0.7]: pred = deepcopy(pred_val) # if predicted proba >= 0.5, this label is set to 1. if all probas < 0.5, the label with largest proba is set to 1 for i in range(pred.shape[0]): if len(np.where(pred[i] >= th)[0]) > 0: pred[i][pred[i] >= th] = 1 pred[i][pred[i] < th] = 0 else: max_index = np.argmax(pred[i]) pred[i] = 0 pred[i][max_index] = 1 # In[ ]: acc_val = hamming_score(y_val, pred) p_val, r_val, f1_val = f1(y_val, pred) print('Eval====>Th: {}, Acc: {}, P: {}, R: {}, F1: {}'.format( th, acc_val, p_val, r_val, f1_val)) # In[ ]: pred = deepcopy(pred_test) for i in range(pred.shape[0]): if len(np.where(pred[i] >= th)[0]) > 0: pred[i][pred[i] >= th] = 1 pred[i][pred[i] < th] = 0 else: max_index = np.argmax(pred[i]) pred[i] = 0