code: def save_model(
      model,
      model_name: str,
      prep_pipe_=None,
      verbose: bool = True,
      use_case: Optional[MLUsecase] = None,
      **kwargs,
  ):
      """
      This generic function saves the transformation pipeline and trained model object
      into the current active directory as a pickle file for later use.
  
      Parameters
      ----------
      model : object
          A trained model object should be passed as an estimator.
  
      model_name : str
          Name of pickle file to be passed as a string.
  
      prep_pipe_ : Pipeline, default = None
          If not None, will save the entire Pipeline in addition to model.
  
      **kwargs:
          Additional keyword arguments to pass to joblib.dump().
  
      verbose: bool, default = True
          Success message is not printed when verbose is set to False.
  
      Returns
      -------
      (model, model_filename):
          Tuple of the model object and the filename it was saved under.
  
      """
  
      function_params_str = ", ".join(
          [f"{k}={v}" for k, v in locals().items()]
      )
  
      logger = get_logger()
  
      logger.info("Initializing save_model()")
      logger.info(f"save_model({function_params_str})")
  
      from copy import deepcopy
  
      logger.info("Adding model into prep_pipe")
  
      if use_case == MLUsecase.TIME_SERIES:
          from pycaret.utils.time_series.forecasting.pipeline import (
              _add_model_to_pipeline,
          )
  
          if prep_pipe_:
              pipeline = deepcopy(prep_pipe_)
              model = _add_model_to_pipeline(
                  pipeline=pipeline, model=model
              )
          else:
              logger.warning(
                  "Only Model saved. Transformations in prep_pipe are ignored."
              )
      else:
          if isinstance(model, Pipeline):
              logger.warning("Only Model saved as it was a pipeline.")
          elif not prep_pipe_:
              logger.warning(
                  "Only Model saved. Transformations in prep_pipe are ignored."
              )
          else:
              model_ = deepcopy(prep_pipe_)
              model_.steps.append(("trained_model", model))
              model = model_
  
      model_name = f"{model_name}.pkl"
      joblib.dump(model, model_name, **kwargs)
      if verbose:
          if prep_pipe_:
              pipe_msg = "Transformation Pipeline and "
          else:
              pipe_msg = ""
          print(f"{pipe_msg}Model Successfully Saved")
  
      logger.info(f"{model_name} saved in current working directory")
      logger.info(str(model))
      logger.info(
          "save_model() successfully completed......................................"
      )
      gc.collect()
      return model, model_name
  
file_path: pycaret/pycaret/internal/persistence.py
imports: import gc
  import os
  from typing import Dict, Optional
  import joblib
  from sklearn.pipeline import Pipeline
  from pycaret.utils._dependencies import _check_soft_dependencies
  from pycaret.utils.generic import MLUsecase, get_logger
label_desc: Use image node_id 2 for calling a global function with example usage: save_model(model, model_name, prep_pipe_, verbose, use_case) and returns: model,  model_name