val_label_all = [] 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:
# y_target_2: np.transpose([test_label_inst_2]) cur_test_loss_2 = sess.run(loss_2, feed_dict={ \ 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)