(y_true, y_pred)
return f1
tensorflow版 序列二分类f1
    :param y_true:
    :param y_pred:
    :return:
tensorflow版 序列二分类f1
    :param y_true:
    :param y_pred:
    :return:
tensorflow版 序列二分类f1 : param y_true : : param y_pred : : return :
def metrics_f1(y_true, y_pred):
    '''
    tensorflow版 序列二分类f1
    :param y_true:
    :param y_pred:
    :return:
    '''
    y_pred = tf.where(y_pred < 0.5, x=tf.zeros_like(y_pred), y=tf.ones_like(y_pred))
    equal_num = tf.count_nonzero(tf.multiply(y_true, y_pred))
    true_sum=tf.count_nonzero(y_true)
    pred_sum=tf.count_nonzero(y_pred)
    precision = equal_num / pred_sum
    recall = equal_num / true_sum
    f1 = (2 * precision * recall) / (precision + recall)
    return f1
def metrics_f1 ( y_true , y_pred ) : y_pred = tf . where ( y_pred < 0.5 , x = tf . zeros_like ( y_pred ) , y = tf . ones_like ( y_pred ) ) equal_num = tf . count_nonzero ( tf . multiply ( y_true , y_pred ) ) true_sum = tf . count_nonzero ( y_true ) pred_sum = tf . count_nonzero ( y_pred ) precision = equal_num / pred_sum recall = equal_num / true_sum f1 = ( 2 * precision * recall ) / ( precision + recall ) return f1