class_docstr: Construct an estimator per data group. Splits data by values of a single column and fits one estimator per such
  column.
  
  Parameters
  ----------
  estimator : scikit-learn compatible estimator/pipeline
      The estimator/pipeline to be applied per group.
  groups : int | str | List[int] | List[str]
      The column(s) of the array/dataframe to select as a grouping parameter set.
  shrinkage : Literal["constant", "min_n_obs", "relative"] | Callable | None, default=None
      How to perform shrinkage:
  
      - `None`: No shrinkage (default)
      - `"constant"`: shrunk prediction for a level is weighted average of its prediction and its parents prediction
      - `"min_n_obs"`: shrunk prediction is the prediction for the smallest group with at least n observations in it
      - `"relative"`: each group-level is weight according to its size
      - `Callable`: a function that takes a list of group lengths and returns an array of the same size with the
          weights for each group
  use_global_model : bool, default=True
  
      - With shrinkage: whether to have a model over the entire input as first group
      - Without shrinkage: whether or not to fall back to a general model in case the group parameter is not found
          during `.predict()`
  check_X : bool, default=True
      Whether to validate `X` to be non-empty 2D array of finite values and attempt to cast `X` to float.
      If disabled, the model/pipeline is expected to handle e.g. missing, non-numeric, or non-finite values.
  **shrinkage_kwargs : dict
      Keyword arguments to the shrinkage function
class_docstr_tok: ["Construct","an","estimator","per","data","group",".","Splits","data","by","values","of","a","single","column","and","fits","one","estimator","per","such","column",".","Parameters","--","--","--","--","--","estimator",":","scikit-learn","compatible","estimator\/pipeline","The","estimator\/pipeline","to","be","applied","per","group",".","groups",":","int","|","str","|","List","[","int","]","|","List","[","str","]","The","column","(","s",")","of","the","array\/dataframe","to","select","as","a","grouping","parameter","set",".","shrinkage",":","Literal","[","``","constant","''",",","``","min_n_obs","''",",","``","relative","''","]","|","Callable","|","None",",","default=None","How","to","perform","shrinkage",":","-","`","None","`",":","No","shrinkage","(","default",")","-","`","``","constant","''","`",":","shrunk","prediction","for","a","level","is","weighted","average","of","its","prediction","and","its","parents","prediction","-","`","``","min_n_obs","''","`",":","shrunk","prediction","is","the","prediction","for","the","smallest","group","with","at","least","n","observations","in","it","-","`","``","relative","''","`",":","each","group-level","is","weight","according","to","its","size","-","`","Callable","`",":","a","function","that","takes","a","list","of","group","lengths","and","returns","an","array","of","the","same","size","with","the","weights","for","each","group","use_global_model",":","bool",",","default=True","-","With","shrinkage",":","whether","to","have","a","model","over","the","entire","input","as","first","group","-","Without","shrinkage",":","whether","or","not","to","fall","back","to","a","general","model","in","case","the","group","parameter","is","not","found","during","`",".predict","(",")","`","check_X",":","bool",",","default=True","Whether","to","validate","`","X","`","to","be","non-empty","2D","array","of","finite","values","and","attempt","to","cast","`","X","`","to","float",".","If","disabled",",","the","model\/pipeline","is","expected","to","handle","e.g",".","missing",",","non-numeric",",","or","non-finite","values",".","*","*","shrinkage_kwargs",":","dict","Keyword","arguments","to","the","shrinkage","function"]
code: def __set_shrinkage_function(self):
      if (
          self.shrinkage
          and len(as_list(self.groups)) == 1
          and not self.use_global_model
      ):
          raise ValueError(
              "Cannot do shrinkage with a single group if use_global_model is False"
          )
  
      if isinstance(self.shrinkage, str):
          # Predefined shrinkage functions
          shrink_options = {
              "constant": constant_shrinkage,
              "relative": relative_shrinkage,
              "min_n_obs": min_n_obs_shrinkage,
          }
  
          try:
              self.shrinkage_function_ = shrink_options[self.shrinkage]
          except KeyError:
              raise ValueError(
                  f"The specified shrinkage function {self.shrinkage} is not valid, "
                  f"choose from {list(shrink_options.keys())} or supply a callable."
              )
      elif callable(self.shrinkage):
          self.__check_shrinkage_func()
          self.shrinkage_function_ = self.shrinkage
      else:
          raise ValueError(
              "Invalid shrinkage specified. Should be either None (no shrinkage), str or callable."
          )
  
imports: import numpy
  import pandas
  from sklearn import clone
  from sklearn.base import BaseEstimator, is_classifier
  from sklearn.utils.metaestimators import available_if
  from sklearn.utils.validation import check_array, check_is_fitted
  from sklego.common import as_list, expanding_list
  from sklego.meta._grouped_utils import _split_groups_and_values, constant_shrinkage, min_n_obs_shrinkage, relative_shrinkage
label_desc: Use image node_id 2 for calling the GroupedPredictor obj's underlying member method code with example usage: obj.__set_shrinkage_function() without return types