class_docstr: Half Binomial deviance loss with logit link, for binary classification.
  
  This is also know as binary cross entropy, log-loss and logistic loss.
  
  Domain:
  y_true in [0, 1], i.e. regression on the unit interval
  y_pred in (0, 1), i.e. boundaries excluded
  
  Link:
  y_pred = expit(raw_prediction)
  
  For a given sample x_i, half Binomial deviance is defined as the negative
  log-likelihood of the Binomial/Bernoulli distribution and can be expressed
  as::
  
      loss(x_i) = log(1 + exp(raw_pred_i)) - y_true_i * raw_pred_i
  
  See The Elements of Statistical Learning, by Hastie, Tibshirani, Friedman,
  section 4.4.1 (about logistic regression).
  
  Note that the formulation works for classification, y = {0, 1}, as well as
  logistic regression, y = [0, 1].
  If you add `constant_to_optimal_zero` to the loss, you get half the
  Bernoulli/binomial deviance.
  
  More details: Inserting the predicted probability y_pred = expit(raw_prediction)
  in the loss gives the well known::
  
      loss(x_i) = - y_true_i * log(y_pred_i) - (1 - y_true_i) * log(1 - y_pred_i)
class_docstr_tok: ["Half","Binomial","deviance","loss","with","logit","link",",","for","binary","classification",".","This","is","also","know","as","binary","cross","entropy",",","log-loss","and","logistic","loss",".","Domain",":","y_true","in","[","0",",","1","]",",","i.e",".","regression","on","the","unit","interval","y_pred","in","(","0",",","1",")",",","i.e",".","boundaries","excluded","Link",":","y_pred","=","expit","(","raw_prediction",")","For","a","given","sample","x_i",",","half","Binomial","deviance","is","defined","as","the","negative","log-likelihood","of","the","Binomial\/Bernoulli","distribution","and","can","be","expressed","as",":",":","loss","(","x_i",")","=","log","(","1","+","exp","(","raw_pred_i",")",")","-","y_true_i","*","raw_pred_i","See","The","Elements","of","Statistical","Learning",",","by","Hastie",",","Tibshirani",",","Friedman",",","section","4.4.1","(","about","logistic","regression",")",".","Note","that","the","formulation","works","for","classification",",","y","=","{","0",",","1","}",",","as","well","as","logistic","regression",",","y","=","[","0",",","1","]",".","If","you","add","`","constant_to_optimal_zero","`","to","the","loss",",","you","get","half","the","Bernoulli\/binomial","deviance",".","More","details",":","Inserting","the","predicted","probability","y_pred","=","expit","(","raw_prediction",")","in","the","loss","gives","the","well","known",":",":","loss","(","x_i",")","=","-","y_true_i","*","log","(","y_pred_i",")","-","(","1","-","y_true_i",")","*","log","(","1","-","y_pred_i",")"]
code: def constant_to_optimal_zero(self, y_true, sample_weight=None):
      # This is non-zero only if y_true is neither 0 nor 1.
      term = xlogy(y_true, y_true) + xlogy(1 - y_true, 1 - y_true)
      if sample_weight is not None:
          term *= sample_weight
      return term
  
imports: import numbers
  import numpy
  from scipy.special import xlogy
  from ..utils import check_scalar
  from ..utils.stats import _weighted_percentile
  from ._loss import CyAbsoluteError, CyExponentialLoss, CyHalfBinomialLoss, CyHalfGammaLoss, CyHalfMultinomialLoss, CyHalfPoissonLoss, CyHalfSquaredError, CyHalfTweedieLoss, CyHalfTweedieLossIdentity, CyHuberLoss, CyPinballLoss
  from .link import HalfLogitLink, IdentityLink, Interval, LogitLink, LogLink, MultinomialLogit
label_desc: Use image node_id 2 for calling the HalfBinomialLoss obj's underlying member method code with example usage: obj.constant_to_optimal_zero(y_true, sample_weight) and returns: term