class_docstr: General class for loss functions with raw_prediction = X @ coef + intercept.
  
  Note that raw_prediction is also known as linear predictor.
  
  The loss is the average of per sample losses and includes a term for L2
  regularization::
  
      loss = 1 / s_sum * sum_i s_i loss(y_i, X_i @ coef + intercept)
             + 1/2 * l2_reg_strength * ||coef||_2^2
  
  with sample weights s_i=1 if sample_weight=None and s_sum=sum_i s_i.
  
  Gradient and hessian, for simplicity without intercept, are::
  
      gradient = 1 / s_sum * X.T @ loss.gradient + l2_reg_strength * coef
      hessian = 1 / s_sum * X.T @ diag(loss.hessian) @ X
                + l2_reg_strength * identity
  
  Conventions:
      if fit_intercept:
          n_dof =  n_features + 1
      else:
          n_dof = n_features
  
      if base_loss.is_multiclass:
          coef.shape = (n_classes, n_dof) or ravelled (n_classes * n_dof,)
      else:
          coef.shape = (n_dof,)
  
      The intercept term is at the end of the coef array:
      if base_loss.is_multiclass:
          if coef.shape (n_classes, n_dof):
              intercept = coef[:, -1]
          if coef.shape (n_classes * n_dof,)
              intercept = coef[n_features::n_dof] = coef[(n_dof-1)::n_dof]
          intercept.shape = (n_classes,)
      else:
          intercept = coef[-1]
  
  Note: If coef has shape (n_classes * n_dof,), the 2d-array can be reconstructed as
  
      coef.reshape((n_classes, -1), order="F")
  
  The option order="F" makes coef[:, i] contiguous. This, in turn, makes the
  coefficients without intercept, coef[:, :-1], contiguous and speeds up
  matrix-vector computations.
  
  Note: If the average loss per sample is wanted instead of the sum of the loss per
  sample, one can simply use a rescaled sample_weight such that
  sum(sample_weight) = 1.
  
  Parameters
  ----------
  base_loss : instance of class BaseLoss from sklearn._loss.
  fit_intercept : bool
docstr: Allocate coef of correct shape with zeros.
  
  Parameters:
  -----------
  X : {array-like, sparse matrix} of shape (n_samples, n_features)
      Training data.
  dtype : data-type, default=None
      Overrides the data type of coef. With dtype=None, coef will have the same
      dtype as X.
  
  Returns
  -------
  coef : ndarray of shape (n_dof,) or (n_classes, n_dof)
      Coefficients of a linear model.
docstr_tok: ["Allocate","coef","of","correct","shape","with","zeros",".","Parameters",":","--","--","--","--","--","-","X",":","{","array-like",",","sparse","matrix","}","of","shape","(","n_samples",",","n_features",")","Training","data",".","dtype",":","data-type",",","default=None","Overrides","the","data","type","of","coef",".","With","dtype=None",",","coef","will","have","the","same","dtype","as","X",".","Returns","--","--","--","-","coef",":","ndarray","of","shape","(","n_dof",",",")","or","(","n_classes",",","n_dof",")","Coefficients","of","a","linear","model","."]
code: def init_zero_coef(self, X, dtype=None):
      """Allocate coef of correct shape with zeros.
  
      Parameters:
      -----------
      X : {array-like, sparse matrix} of shape (n_samples, n_features)
          Training data.
      dtype : data-type, default=None
          Overrides the data type of coef. With dtype=None, coef will have the same
          dtype as X.
  
      Returns
      -------
      coef : ndarray of shape (n_dof,) or (n_classes, n_dof)
          Coefficients of a linear model.
      """
      n_features = X.shape[1]
      n_classes = self.base_loss.n_classes
      if self.fit_intercept:
          n_dof = n_features + 1
      else:
          n_dof = n_features
      if self.base_loss.is_multiclass:
          coef = np.zeros_like(
              X, shape=(n_classes, n_dof), dtype=dtype, order="F"
          )
      else:
          coef = np.zeros_like(X, shape=n_dof, dtype=dtype)
      return coef
  
file_path: scikit-learn/sklearn/linear_model/_linear_loss.py
imports: import numpy
  from scipy import sparse
  from ..utils.extmath import squared_norm
label_desc: Use image node_id 2 for calling the LinearModelLoss obj's underlying member method code with example usage: obj.init_zero_coef(X, dtype) and returns: coef