class_docstr: Computes the hinge loss.
  
  Mathematically, it is defined as
  
  $$L = max(0, 1 - p_i * y_i)$$
  
  It's gradient w.r.t. to $p_i$ is
  
  $$
  \\frac{\\partial L}{\\partial y_i} = \\left\{
  \\begin{array}{ll}
      \\ 0  &   p_iy_i \geqslant 1  \\\\
      \\ - y_i & p_iy_i < 1
  \\end{array}
  \\right.
  $$
  
  Parameters
  ----------
  threshold
      Margin threshold. 1 yield the loss used in SVMs, whilst 0 is equivalent to the loss used in
      the Perceptron algorithm.
  
  Examples
  --------
  
  >>> from river import optim
  
  >>> loss = optim.losses.Hinge(threshold=1)
  >>> loss(1, .2)
  0.8
  
  >>> loss.gradient(1, .2)
  -1
class_docstr_tok: ["Computes","the","hinge","loss",".","Mathematically",",","it","is","defined","as","$","$","L","=","max","(","0",",","1","-","p_i","*","y_i",")","$","$","It","'s","gradient","w.r.t",".","to","$","p_i","$","is","$","$","\\\\frac","{","\\\\partial","L","}","{","\\\\partial","y_i","}","=","\\\\left\\","{","\\\\begin","{","array","}","{","ll","}","\\\\","0","&","p_iy_i","\\geqslant","1","\\\\\\\\","\\\\","-","y_i","&","p_iy_i","<","1","\\\\end","{","array","}","\\\\right",".","$","$","Parameters","--","--","--","--","--","threshold","Margin","threshold",".","1","yield","the","loss","used","in","SVMs",",","whilst","0","is","equivalent","to","the","loss","used","in","the","Perceptron","algorithm",".","Examples","--","--","--","--",">",">",">","from","river","import","optim",">",">",">","loss","=","optim.losses.Hinge","(","threshold=1",")",">",">",">","loss","(","1",",",".2",")","0.8",">",">",">","loss.gradient","(","1",",",".2",")","-1"]
code: def __call__(self, y_true, y_pred):
      y_true = y_true * 2 - 1  # [0, 1] -> [-1, 1]
  
      if isinstance(y_true, np.ndarray):
          return np.maximum(self.threshold - y_true * y_pred, 0)
  
      return max(self.threshold - y_true * y_pred, 0)
  
imports: from __future__ import annotations
  import math
  import numpy
  from scipy import special
  from river import base, utils
  from river.optim.base import Loss
label_desc: Use image node_id 2 for calling the Hinge obj's underlying member method code with example usage: obj.__call__(y_true, y_pred) and returns: max, np