unexplained_error = tf.reduce_sum(tf.square(labels - predictions)) total_error = tf.reduce_sum(tf.square(labels - tf.reduce_mean(labels, axis=0))) R2 = 1. - tf.div(unexplained_error, total_error)