(sess, model, x_, y_)
return total_loss / data_len, f1_score, confuse_matrix, y_pred, y_target
评估 val data 的准确率和损失
评估 val data 的准确率和损失
评估 val data 的准确率和损失
def evaluate(sess, model, x_, y_):
    """
    评估 val data 的准确率和损失
    """
    data_len = len(x_)
    batch_eval = batch_iter(x_, y_, 64, shuffle=False)
    total_loss = 0.0
    y_pred = []
    y_target = []
    for x_batch, y_batch in batch_eval:
        batch_len = len(x_batch)
        feed_dict = {model.input_x: x_batch, model.input_y: y_batch,
                     model.drop_prob: 0}
        loss, logits = sess.run([model.loss, model.logits], feed_dict=feed_dict)
        total_loss += loss * batch_len
        y_batch_pred = get_logits_label(logits)
        y_batch_target = get_target_label(y_batch)
        y_pred.extend(y_batch_pred)
        y_target.extend(y_batch_target)

    confuse_matrix = compute_confuse_matrix(y_target, y_pred)
    f1_micro, f1_macro = compute_micro_macro(confuse_matrix)
    print(f1_micro, f1_macro)
    f1_score = (f1_micro + f1_macro) / 2.0

    return total_loss / data_len, f1_score, confuse_matrix, y_pred, y_target
def evaluate ( sess , model , x_ , y_ ) : data_len = len ( x_ ) batch_eval = batch_iter ( x_ , y_ , 64 , shuffle = False ) total_loss = 0.0 y_pred = [ ] y_target = [ ] for x_batch , y_batch in batch_eval : batch_len = len ( x_batch ) feed_dict = { model . input_x : x_batch , model . input_y : y_batch , model . drop_prob : 0 } loss , logits = sess . run ( [ model . loss , model . logits ] , feed_dict = feed_dict ) total_loss += loss * batch_len y_batch_pred = get_logits_label ( logits ) y_batch_target = get_target_label ( y_batch ) y_pred . extend ( y_batch_pred ) y_target . extend ( y_batch_target ) confuse_matrix = compute_confuse_matrix ( y_target , y_pred ) f1_micro , f1_macro = compute_micro_macro ( confuse_matrix ) print ( f1_micro , f1_macro ) f1_score = ( f1_micro + f1_macro ) / 2.0 return total_loss / data_len , f1_score , confuse_matrix , y_pred , y_target