code: def regress_artifact(
      inst,
      picks=None,
      *,
      exclude="bads",
      picks_artifact="eog",
      betas=None,
      proj=True,
      copy=True,
      verbose=None,
  ):
      """Remove artifacts using regression based on reference channels.
  
      Parameters
      ----------
      inst : instance of Epochs | Raw
          The instance to process.
      %(picks_good_data)s
      exclude : list | 'bads'
          List of channels to exclude from the regression, only used when picking
          based on types (e.g., exclude="bads" when picks="meg").
          Specify ``'bads'`` (the default) to exclude all channels marked as bad.
  
          .. versionadded:: 1.2
      picks_artifact : array-like | str
          Channel picks to use as predictor/explanatory variables capturing
          the artifact of interest (default is "eog").
      betas : ndarray, shape (n_picks, n_picks_ref) | None
          The regression coefficients to use. If None (default), they will be
          estimated from the data.
      proj : bool
          Whether to automatically apply SSP projection vectors before performing
          the regression. Default is ``True``.
      copy : bool
          If True (default), copy the instance before modifying it.
      %(verbose)s
  
      Returns
      -------
      inst : instance of Epochs | Raw
          The processed data.
      betas : ndarray, shape (n_picks, n_picks_ref)
          The betas used during regression.
  
      Notes
      -----
      To implement the method outlined in :footcite:`GrattonEtAl1983`,
      remove the evoked response from epochs before estimating the
      regression coefficients, then apply those regression coefficients to the
      original data in two calls like (here for a single-condition ``epochs``
      only):
  
          >>> epochs_no_ave = epochs.copy().subtract_evoked()  # doctest:+SKIP
          >>> _, betas = mne.preprocessing.regress(epochs_no_ave)  # doctest:+SKIP
          >>> epochs_clean, _ = mne.preprocessing.regress(epochs, betas=betas)  # doctest:+SKIP
  
      References
      ----------
      .. footbibliography::
      """  # noqa: E501
      if betas is None:
          model = EOGRegression(
              picks=picks,
              exclude=exclude,
              picks_artifact=picks_artifact,
              proj=proj,
          )
          model.fit(inst)
      else:
          # Create an EOGRegression object and load the given betas into it.
          picks = _picks_to_idx(
              inst.info, picks, exclude=exclude, none="data"
          )
          picks_artifact = _picks_to_idx(inst.info, picks_artifact)
          want_betas_shape = (len(picks), len(picks_artifact))
          _check_option("betas.shape", betas.shape, (want_betas_shape,))
          model = EOGRegression(picks, picks_artifact, proj=proj)
          model.info_ = inst.info.copy()
          model.coef_ = betas
      return model.apply(inst, copy=copy), model.coef_
  
file_path: mne-python/mne/preprocessing/_regress.py
imports: import numpy
  from .._fiff.pick import _picks_to_idx
  from ..defaults import _BORDER_DEFAULT, _EXTRAPOLATE_DEFAULT, _INTERPOLATION_DEFAULT
  from ..epochs import BaseEpochs
  from ..evoked import Evoked
  from ..io import BaseRaw
  from ..minimum_norm.inverse import _needs_eeg_average_ref_proj
  from ..utils import _check_fname, _check_option, _check_preload, _import_h5io_funcs, _validate_type, copy_function_doc_to_method_doc, fill_doc, verbose
  from ..viz import plot_regression_weights
label_desc: Use image node_id 1 for calling a global function with example usage: regress_artifact(inst, picks) and returns: model,  model