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: Compute L2 penalty term l2_reg_strength/2 *||w||_2^2.
docstr_tok: ["Compute","L2","penalty","term","l2_reg_strength\/2","*","||w||_2^2","."]
code: def l2_penalty(self, weights, l2_reg_strength):
      """Compute L2 penalty term l2_reg_strength/2 *||w||_2^2."""
      norm2_w = (
          weights @ weights
          if weights.ndim == 1
          else squared_norm(weights)
      )
      return 0.5 * l2_reg_strength * norm2_w
  
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 5 for calling the LinearModelLoss obj's underlying member method code with example usage: obj.l2_penalty(weights, l2_reg_strength) and returns: unknown