Skip to contents

For example, if values is c(1, 3, 5, 7) then the mean is 4. If sample_weight was specified as c(1, 1, 0, 0) then the mean would be 2.

This metric creates two variables, total and count. The mean value returned is simply total divided by count.

Usage

metric_mean(..., name = "mean", dtype = NULL)

Arguments

...

For forward/backward compatability.

name

(Optional) string name of the metric instance.

dtype

(Optional) data type of the metric result.

Value

a Metric instance is returned. The Metric instance can be passed directly to compile(metrics = ), or used as a standalone object. See ?Metric for example usage.

Examples

m <- metric_mean()
m$update_state(c(1, 3, 5, 7))
m$result()

## tf.Tensor(4.0, shape=(), dtype=float32)

m$reset_state()
m$update_state(c(1, 3, 5, 7), sample_weight = c(1, 1, 0, 0))
m$result()

## tf.Tensor(2.0, shape=(), dtype=float32)