code: def process_bag_terms(n_classes, term_scores, bin_weights):
      if n_classes == 1:
          intercept = -np.inf
      elif n_classes <= 2:
          intercept = 0
      else:
          intercept = np.zeros(n_classes, np.float64)
  
      for scores, weights in zip(term_scores, bin_weights):
          if n_classes <= 2:
              temp_scores = scores.flatten().copy()
              temp_weights = weights.flatten().copy()
  
              ignored = np.isinf(temp_scores)
              ignored |= np.isnan(temp_scores)
              temp_scores[ignored] = 0.0
              temp_weights[ignored] = 0.0
  
              if temp_weights.sum() != 0:
                  mean = np.average(temp_scores, 0, temp_weights)
                  intercept += mean
                  scores -= mean
          else:
              for i in range(n_classes):
                  temp_scores = scores[..., i].flatten().copy()
                  temp_weights = weights.flatten().copy()
  
                  ignored = np.isinf(temp_scores)
                  ignored |= np.isnan(temp_scores)
                  temp_scores[ignored] = 0.0
                  temp_weights[ignored] = 0.0
  
                  if temp_weights.sum() != 0:
                      mean = np.average(temp_scores, 0, temp_weights)
                      intercept[i] += mean
                      scores[..., i] -= mean
  
          # TODO: call purify() here from the glassbox\ebm\_research\_purify.py file
  
          # TODO: for multiclass, call a fixed version of multiclass_postprocess_RESTORE_THIS
          #       That implementation has a bug where it always uses the simpler
          #       method of taking the mean of the class scores.
  
          # if the missing/unknown bin has zero weight then whatever number was generated via boosting is
          # effectively meaningless and can be ignored. Set the value to zero for interpretability reasons
  
          if n_classes != 1:
              restore_missing_value_zeros(scores, weights)
      return intercept
  
imports: from math import ceil, isnan, isinf, exp, log
  from ...utils._native import Native
  from ._tensor import restore_missing_value_zeros
  import numpy
  import warnings
  from itertools import islice
  import logging
label_desc: Use image node_id 4 for calling a global function with example usage: process_bag_terms(n_classes, term_scores, bin_weights) and returns: intercept