perceptron_loss

Contents

perceptron_loss#

class braintools.metric.perceptron_loss(predictor_outputs, targets)#

Compute the binary perceptron loss.

The perceptron loss is used in the original perceptron algorithm [1] for binary classification. It penalizes misclassified examples by the magnitude of the prediction error.

The perceptron loss is defined as: max(0, -y * f(x)) where y is the true class label and f(x) is the predicted output.

Parameters:
  • predictor_outputs (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Scores produced by the model. Real-valued predictions.

  • targets (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Target values. Must be in the set {-1, 1} for binary classification. Shape must match predictor_outputs.

Returns:

Perceptron loss values with the same shape as the input arrays.

Return type:

Array | ndarray | bool | number | bool | int | float | complex | Quantity

Examples

>>> import jax.numpy as jnp
>>> import braintools
>>> predictions = jnp.array([1.0, -0.5, 2.0])
>>> targets = jnp.array([1, -1, 1])
>>> loss = braintools.metric.perceptron_loss(predictions, targets)
>>> print(loss)
[0. 0. 0.]

References