code: def model_action(
      model,
      X_train,
      y_train,
      X_test,
      sample_weight=None,
      action=None,
      transform=None,
  ):
      """Performs model action.
      This wrapper gives us ability to choose action dynamically
      (e.g. predict or predict_proba).
      Note. Through <model_action> and then through <transformer> we
      apply <transform_target> and <transform_pred> functions if given by user
      on the target and prediction in each fold separately
      to be able to calculate proper scores
      """
      if "fit" == action:
          # We use following condition, because some models (e.g. Lars) may not have
          # 'sample_weight' parameter of fit method
          if sample_weight is not None:
              return model.fit(
                  X_train,
                  transformer(y_train, func=transform),
                  sample_weight=sample_weight,
              )
          else:
              return model.fit(
                  X_train, transformer(y_train, func=transform)
              )
      elif "predict" == action:
          return transformer(model.predict(X_test), func=transform)
      elif "predict_proba" == action:
          return transformer(
              model.predict_proba(X_test), func=transform
          )
      else:
          raise ValueError("Parameter action must be set properly")
  
file_path: vecstack/vecstack/core.py
imports: from __future__ import print_function
  from __future__ import division
  import os
  import sys
  import warnings
  from datetime import datetime
  import numpy
  import scipy.stats
  from sklearn.model_selection import KFold
  from sklearn.model_selection import StratifiedKFold
  from sklearn.metrics import mean_absolute_error
  from sklearn.metrics import accuracy_score
  from sklearn.metrics import log_loss
  from sklearn.utils.validation import check_X_y
  from sklearn.utils.validation import check_array
  from sklearn.base import clone
label_desc: Use image node_id 2 for calling a global function with example usage: model_action(model, X_train, y_train, X_test, sample_weight, action, transform) and returns: model, model, transformer, transformer