class_docstr: Main class which validates the passed estimator and
  coordinates the kind of estimator to a concrete subclass.
docstr: Extract the original estimator.
  
  Check if the estimator is a valid base estimator of scikit-learn.
  Check if the estimator is embedded in an optimizer or pipeline.
  Check if the estimator is a classifier or regressor.
  
  Parameters
  ----------
  estimator : BaseEstimator
      Set a fitted base estimator of scikit-learn.
  
  Returns
  -------
  A valid base estimator or None.
docstr_tok: ["Extract","the","original","estimator",".","Check","if","the","estimator","is","a","valid","base","estimator","of","scikit-learn",".","Check","if","the","estimator","is","embedded","in","an","optimizer","or","pipeline",".","Check","if","the","estimator","is","a","classifier","or","regressor",".","Parameters","--","--","--","--","--","estimator",":","BaseEstimator","Set","a","fitted","base","estimator","of","scikit-learn",".","Returns","--","--","--","-","A","valid","base","estimator","or","None","."]
code: def _extract_est(estimator: BaseEstimator) -> Optional[BaseEstimator]:
      """
      Extract the original estimator.
  
      Check if the estimator is a valid base estimator of scikit-learn.
      Check if the estimator is embedded in an optimizer or pipeline.
      Check if the estimator is a classifier or regressor.
  
      Parameters
      ----------
      estimator : BaseEstimator
          Set a fitted base estimator of scikit-learn.
  
      Returns
      -------
      A valid base estimator or None.
      """
      est = estimator  # shorter <3
      qualname = _get_qualname(est)
  
      L.debug(
          "Start validation of the passed "
          "estimator: `{}`.".format(qualname)
      )
  
      # Check BaseEstimator:
      if not isinstance(est, BaseEstimator):
          msg = (
              "The passed estimator `{}` is not a "
              "valid base estimator of scikit-learn v{} ."
              "".format(qualname, sklearn_version)
          )
          L.error(msg)
          raise ValueError(msg)
  
      # Check BaseEnsemble:
      if isinstance(est, BaseEnsemble):
          try:
              est.estimators_  # for sklearn > 0.19
          except AttributeError:
              raise exception.NotFittedEstimatorError(qualname)
          try:
              est.estimators_[0]  # for sklearn <= 0.18
          except IndexError:
              raise exception.NotFittedEstimatorError(qualname)
  
      # Check GridSearchCV and RandomizedSearchCV:
      L.debug(
          "Check whether the estimator is embedded in an optimizer."
      )
      try:
          from sklearn.model_selection._search import (
              BaseSearchCV,
          )  # pylint: disable=protected-access
      except ImportError:
          msg = (
              "Your installed version of scikit-learn v{} "
              "does not support optimizers in general."
              "".format(sklearn_version)
          )
          L.warning(msg)
      else:
          if isinstance(est, BaseSearchCV):
              L.debug(
                  "└> Yes, the estimator is embedded in an optimizer."
              )
              try:
                  from sklearn.model_selection import GridSearchCV
                  from sklearn.model_selection import RandomizedSearchCV
              except ImportError:
                  msg = (
                      "Your installed version of scikit-learn "
                      "v{} does not support `GridSearchCV` or "
                      "`RandomizedSearchCV`.".format(sklearn_version)
                  )
                  L.warning(msg)
              else:
                  optimizers = (GridSearchCV, RandomizedSearchCV)
                  if isinstance(est, optimizers):
                      # pylint: disable=protected-access
                      is_fitted = (
                          hasattr(est, "best_estimator_")
                          and est.best_estimator_
                      )
                      if is_fitted:
                          est = est.best_estimator_
                          est_qualname = _get_qualname(est)
                          msg = (
                              "Extract the embedded estimator of "
                              "type `{}` from optimizer `{}`."
                              "".format(est_qualname, qualname)
                          )
                          L.info(msg)
                      # pylint: enable=protected-access
                      else:
                          msg = "The embedded estimator is not fitted."
                          L.error(msg)
                          raise ValueError(msg)
                  else:
                      msg = (
                          "The used optimizer `{}` is not supported "
                          "by this version of sklearn-porter. Try to "
                          "extract the internal estimator manually "
                          "and pass it.".format(qualname)
                      )
                      L.error(msg)
                      raise ValueError(msg)
          else:
              L.debug(
                  "└> No, the estimator is not embedded in an optimizer."
              )
  
      # Check Pipeline:
      L.debug("Check whether the estimator is embedded in a pipeline.")
      try:
          from sklearn.pipeline import Pipeline
      except ImportError:
          msg = (
              "Your installed version of scikit-learn "
              "v{} does not support pipelines.".format(sklearn_version)
          )
          L.warning(msg)
      else:
          if isinstance(est, Pipeline):
              L.debug(
                  "└> Yes, the estimator is embedded in a pipeline."
              )
              # pylint: disable=protected-access
              has_est = (
                  hasattr(est, "_final_estimator")
                  and est._final_estimator
              )
              if has_est:
                  est = est._final_estimator
                  est_qualname = _get_qualname(est)
                  msg = (
                      "Extract the embedded estimator of type "
                      "`{}` from the pipeline.".format(est_qualname)
                  )
                  L.info(msg)
              # pylint: enable=protected-access
              else:
                  msg = "There is no final estimator is the pipeline."
                  L.error(msg)
                  raise ValueError(msg)
          else:
              L.debug(
                  "└> No, the estimator is not embedded in a pipeline."
              )
  
      # Check ClassifierMixin:
      L.debug(
          "Check whether the estimator is inherited from `ClassifierMixin`."
      )
      is_classifier = isinstance(est, ClassifierMixin)
      if is_classifier:
          L.debug(
              "└> Yes, the estimator is inherited from `ClassifierMixin`."
          )
          return est
      L.debug(
          "└> No, the estimator is not inherited from `ClassifierMixin`."
      )
  
      # Check RegressorMixin:
      L.debug(
          "Check whether the estimator is inherited from `RegressorMixin`."
      )
      is_regressor = isinstance(est, RegressorMixin)
      if is_regressor:
          L.debug(
              "└> Yes, the estimator is inherited from `RegressorMixin`."
          )
          return est
      L.debug(
          "└> No, the estimator is not inherited from `RegressorMixin`."
      )
  
      if not (is_classifier or is_regressor):
          msg = (
              "The passed object of type `{}` is neither "
              "a classifier nor a regressor."
          ).format(qualname)
          L.error(msg)
          raise ValueError(msg)
  
      return None
  
imports: import urllib.request
  from abc import ABCMeta
  from collections import OrderedDict
  from functools import partial
  from json import JSONDecodeError, loads
  from multiprocessing import Pool, cpu_count
  from os import environ, remove
  from pathlib import Path
  from shutil import which
  from subprocess import STDOUT, CalledProcessError, check_output
  from sys import platform, stdout, version_info
  from tempfile import mktemp
  from textwrap import dedent
  from time import sleep
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import numpy
  from loguru import logger
  from tabulate import tabulate
  from sklearn import __version__
  from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin
  from sklearn.ensemble import BaseEnsemble
  from sklearn.metrics import accuracy_score
  from sklearn_porter import decorators
  from sklearn_porter import enums
  from sklearn_porter import exceptions
  from sklearn_porter import meta
  from sklearn_porter.utils import options
label_desc: Use image node_id 13 for calling the Estimator obj's underlying member method code with example usage: obj._extract_est(estimator) and returns: None, est, est