cur_test_loss = sess.run(loss, feed_dict={ \ x_input:test_ft_inst, \ y_target:test_label_inst, keep_prob:1.0}) test_loss_all.append(cur_test_loss) except tf.errors.OutOfRangeError: func.print_time() print('Done testing -- epoch limit reached') finally: coord.request_stop() coord.join(threads) # calculate auc test_pred_score_re = func.list_flatten(test_pred_score_all) test_label_re = func.list_flatten(test_label_all) test_auc, _, _ = func.cal_auc(test_pred_score_re, test_label_re) test_rmse = func.cal_rmse(test_pred_score_re, test_label_re) test_loss = np.mean(test_loss_all) # rounding test_auc = np.round(test_auc, 4) test_rmse = np.round(test_rmse, 4) test_loss = np.round(test_loss, 5) train_loss_list = [np.round(xx, 4) for xx in train_loss_list] print('test_auc = ', test_auc) print('test_rmse =', test_rmse) print('test_loss =', test_loss) print('train_loss_list =', train_loss_list) # append to result_list
for iii in range(n_val_batch): # get batch start_idx = iii * batch_size end_idx = (iii + 1) * batch_size cur_val_ft = val_ft_inst[start_idx:end_idx] cur_val_label = val_label_inst[start_idx:end_idx] # pred score cur_val_pred_score = sess.run(pred_score, feed_dict={ \ x_input:cur_val_ft, keep_prob:1.0}) val_pred_score_all.append(cur_val_pred_score.flatten()) val_label_all.append(cur_val_label) # calculate auc val_pred_score_re = func.list_flatten(val_pred_score_all) val_label_re = func.list_flatten(val_label_all) val_auc_temp, _, _ = func.cal_auc(val_pred_score_re, val_label_re) # record all val results val_auc_list.append(val_auc_temp) # record best and save models if val_auc_temp > best_val_auc: best_val_auc = val_auc_temp best_n_round = epoch # Save the variables to disk save_path = saver_val.save(sess, model_saving_addr) print("Model saved in: %s" % save_path) # count of consecutive lower if val_auc_temp < best_val_auc: lower_ct += 1 # once higher or equal, set to 0 else:
x_input_2:test_ft_inst_2, \ y_target_2: test_label_inst_2, keep_prob:1.0}) test_loss_all_2.append(cur_test_loss_2) except tf.errors.OutOfRangeError: func.print_time() print('Done testing 2 -- epoch limit reached') finally: coord.request_stop() coord.join(threads) ################################# # calculate auc test_pred_score_re_1 = func.list_flatten(test_pred_score_all_1) test_label_re_1 = func.list_flatten(test_label_all_1) test_auc_1, _, _ = func.cal_auc(test_pred_score_re_1, test_label_re_1) test_rmse_1 = func.cal_rmse(test_pred_score_re_1, test_label_re_1) test_loss_1 = np.mean(test_loss_all_1) test_pred_score_re_2 = func.list_flatten(test_pred_score_all_2) test_label_re_2 = func.list_flatten(test_label_all_2) test_auc_2, _, _ = func.cal_auc(test_pred_score_re_2, test_label_re_2) test_rmse_2 = func.cal_rmse(test_pred_score_re_2, test_label_re_2) test_loss_2 = np.mean(test_loss_all_2) # rounding test_auc_1 = np.round(test_auc_1, 4) test_rmse_1 = np.round(test_rmse_1, 4) test_loss_1 = np.round(test_loss_1, 5) test_auc_2 = np.round(test_auc_2, 4)