Keras 2 API documentation / Metrics / Hinge metrics for "maximum-margin" classification

Hinge metrics for "maximum-margin" classification

[source]

Hinge class

tf_keras.metrics.Hinge(name="hinge", dtype=None)

Computes the hinge metric between y_true and y_pred.

y_true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we will convert them to -1 or 1.

Arguments

  • name: (Optional) string name of the metric instance.
  • dtype: (Optional) data type of the metric result.

Standalone usage:

>>> m = tf.keras.metrics.Hinge()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]])
>>> m.result().numpy()
1.3
>>> m.reset_state()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]],
...                sample_weight=[1, 0])
>>> m.result().numpy()
1.1

Usage with compile() API:

model.compile(
    optimizer='sgd', loss='mse', metrics=[tf.keras.metrics.Hinge()])

[source]

SquaredHinge class

tf_keras.metrics.SquaredHinge(name="squared_hinge", dtype=None)

Computes the squared hinge metric between y_true and y_pred.

y_true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we will convert them to -1 or 1.

Arguments

  • name: (Optional) string name of the metric instance.
  • dtype: (Optional) data type of the metric result.

Standalone usage:

>>> m = tf.keras.metrics.SquaredHinge()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]])
>>> m.result().numpy()
1.86
>>> m.reset_state()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]],
...                sample_weight=[1, 0])
>>> m.result().numpy()
1.46

Usage with compile() API:

model.compile(
    optimizer='sgd',
    loss='mse',
    metrics=[tf.keras.metrics.SquaredHinge()])

[source]

CategoricalHinge class

tf_keras.metrics.CategoricalHinge(name="categorical_hinge", dtype=None)

Computes the categorical hinge metric between y_true and y_pred.

Arguments

  • name: (Optional) string name of the metric instance.
  • dtype: (Optional) data type of the metric result.

Standalone usage:

>>> m = tf.keras.metrics.CategoricalHinge()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]])
>>> m.result().numpy()
1.4000001
>>> m.reset_state()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]],
...                sample_weight=[1, 0])
>>> m.result().numpy()
1.2

Usage with compile() API:

model.compile(
    optimizer='sgd',
    loss='mse',
    metrics=[tf.keras.metrics.CategoricalHinge()])