class_docstr: Handle end-to-end training and deployment of custom Scikit-learn code.
class_docstr_tok: ["Handle","end-to-end","training","and","deployment","of","custom","Scikit-learn","code","."]
docstr: Creates a SKLearn Estimator for Scikit-learn environment.
  
  It will execute an Scikit-learn script within a SageMaker Training Job. The managed
  Scikit-learn environment is an Amazon-built Docker container that executes functions
  defined in the supplied ``entry_point`` Python script.
  
  Training is started by calling
  :meth:`~sagemaker.amazon.estimator.Framework.fit` on this Estimator.
  After training is complete, calling
  :meth:`~sagemaker.amazon.estimator.Framework.deploy` creates a hosted
  SageMaker endpoint and returns an
  :class:`~sagemaker.amazon.sklearn.model.SKLearnPredictor` instance that
  can be used to perform inference against the hosted model.
  
  Technical documentation on preparing Scikit-learn scripts for
  SageMaker training and using the Scikit-learn Estimator is available on
  the project home-page: https://github.com/aws/sagemaker-python-sdk
  
  Args:
      entry_point (str or PipelineVariable): Path (absolute or relative) to the Python source
          file which should be executed as the entry point to training.
          If ``source_dir`` is specified, then ``entry_point``
          must point to a file located at the root of ``source_dir``.
      framework_version (str): Scikit-learn version you want to use for
          executing your model training code. Defaults to ``None``. Required
          unless ``image_uri`` is provided. List of supported versions:
          https://docs.aws.amazon.com/sagemaker/latest/dg/sklearn.html
      py_version (str): Python version you want to use for executing your
          model training code (default: 'py3'). Currently, 'py3' is the only
          supported version. If ``None`` is passed in, ``image_uri`` must be
          provided.
      source_dir (str or PipelineVariable): Path (absolute, relative or an S3 URI) to
          a directory with any other training source code dependencies aside from the entry
          point file (default: None). If ``source_dir`` is an S3 URI, it must
          point to a tar.gz file. Structure within this directory are preserved
          when training on Amazon SageMaker.
      hyperparameters (dict[str, str] or dict[str, PipelineVariable]): Hyperparameters
          that will be used for training (default: None). The hyperparameters are made
          accessible as a dict[str, str] to the training code on
          SageMaker. For convenience, this accepts other types for keys
          and values, but ``str()`` will be called to convert them before
          training.
      image_uri (str or PipelineVariable)): If specified, the estimator will use this image
          for training and hosting, instead of selecting the appropriate
          SageMaker official image based on framework_version and
          py_version. It can be an ECR url or dockerhub image and tag.
  
          Examples:
              123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
              custom-image:latest.
  
          If ``framework_version`` or ``py_version`` are ``None``, then
          ``image_uri`` is required. If also ``None``, then a ``ValueError``
          will be raised.
      image_uri_region (str): If ``image_uri`` argument is None, the image uri
          associated with this object will be in this region.
          Default: region associated with SageMaker session.
      **kwargs: Additional kwargs passed to the
          :class:`~sagemaker.estimator.Framework` constructor.
  
  .. tip::
  
      You can find additional parameters for initializing this class at
      :class:`~sagemaker.estimator.Framework` and
      :class:`~sagemaker.estimator.EstimatorBase`.
docstr_tok: ["Creates","a","SKLearn","Estimator","for","Scikit-learn","environment",".","It","will","execute","an","Scikit-learn","script","within","a","SageMaker","Training","Job",".","The","managed","Scikit-learn","environment","is","an","Amazon-built","Docker","container","that","executes","functions","defined","in","the","supplied","``","entry_point","``","Python","script",".","Training","is","started","by","calling",":","meth",":","`","~sagemaker.amazon.estimator.Framework.fit","`","on","this","Estimator",".","After","training","is","complete",",","calling",":","meth",":","`","~sagemaker.amazon.estimator.Framework.deploy","`","creates","a","hosted","SageMaker","endpoint","and","returns","an",":","class",":","`","~sagemaker.amazon.sklearn.model.SKLearnPredictor","`","instance","that","can","be","used","to","perform","inference","against","the","hosted","model",".","Technical","documentation","on","preparing","Scikit-learn","scripts","for","SageMaker","training","and","using","the","Scikit-learn","Estimator","is","available","on","the","project","home-page",":","https",":","\/\/github.com\/aws\/sagemaker-python-sdk","Args",":","entry_point","(","str","or","PipelineVariable",")",":","Path","(","absolute","or","relative",")","to","the","Python","source","file","which","should","be","executed","as","the","entry","point","to","training",".","If","``","source_dir","``","is","specified",",","then","``","entry_point","``","must","point","to","a","file","located","at","the","root","of","``","source_dir","``",".","framework_version","(","str",")",":","Scikit-learn","version","you","want","to","use","for","executing","your","model","training","code",".","Defaults","to","``","None","``",".","Required","unless","``","image_uri","``","is","provided",".","List","of","supported","versions",":","https",":","\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/sklearn.html","py_version","(","str",")",":","Python","version","you","want","to","use","for","executing","your","model","training","code","(","default",":","'py3","'",")",".","Currently",",","'py3","'","is","the","only","supported","version",".","If","``","None","``","is","passed","in",",","``","image_uri","``","must","be","provided",".","source_dir","(","str","or","PipelineVariable",")",":","Path","(","absolute",",","relative","or","an","S3","URI",")","to","a","directory","with","any","other","training","source","code","dependencies","aside","from","the","entry","point","file","(","default",":","None",")",".","If","``","source_dir","``","is","an","S3","URI",",","it","must","point","to","a","tar.gz","file",".","Structure","within","this","directory","are","preserved","when","training","on","Amazon","SageMaker",".","hyperparameters","(","dict","[","str",",","str","]","or","dict","[","str",",","PipelineVariable","]",")",":","Hyperparameters","that","will","be","used","for","training","(","default",":","None",")",".","The","hyperparameters","are","made","accessible","as","a","dict","[","str",",","str","]","to","the","training","code","on","SageMaker",".","For","convenience",",","this","accepts","other","types","for","keys","and","values",",","but","``","str","(",")","``","will","be","called","to","convert","them","before","training",".","image_uri","(","str","or","PipelineVariable",")",")",":","If","specified",",","the","estimator","will","use","this","image","for","training","and","hosting",",","instead","of","selecting","the","appropriate","SageMaker","official","image","based","on","framework_version","and","py_version",".","It","can","be","an","ECR","url","or","dockerhub","image","and","tag",".","Examples",":","123.dkr.ecr.us-west-2.amazonaws.com\/my-custom-image:1.0","custom-image",":","latest",".","If","``","framework_version","``","or","``","py_version","``","are","``","None","``",",","then","``","image_uri","``","is","required",".","If","also","``","None","``",",","then","a","``","ValueError","``","will","be","raised",".","image_uri_region","(","str",")",":","If","``","image_uri","``","argument","is","None",",","the","image","uri","associated","with","this","object","will","be","in","this","region",".","Default",":","region","associated","with","SageMaker","session",".","*","*","kwargs",":","Additional","kwargs","passed","to","the",":","class",":","`","~sagemaker.estimator.Framework","`","constructor",".","..","tip",":",":","You","can","find","additional","parameters","for","initializing","this","class","at",":","class",":","`","~sagemaker.estimator.Framework","`","and",":","class",":","`","~sagemaker.estimator.EstimatorBase","`","."]
code: def __init__(
      self,
      entry_point: Union[str, PipelineVariable],
      framework_version: Optional[str] = None,
      py_version: str = "py3",
      source_dir: Optional[Union[str, PipelineVariable]] = None,
      hyperparameters: Optional[
          Dict[str, Union[str, PipelineVariable]]
      ] = None,
      image_uri: Optional[Union[str, PipelineVariable]] = None,
      image_uri_region: Optional[str] = None,
      **kwargs,
  ):
      """Creates a SKLearn Estimator for Scikit-learn environment.
  
      It will execute an Scikit-learn script within a SageMaker Training Job. The managed
      Scikit-learn environment is an Amazon-built Docker container that executes functions
      defined in the supplied ``entry_point`` Python script.
  
      Training is started by calling
      :meth:`~sagemaker.amazon.estimator.Framework.fit` on this Estimator.
      After training is complete, calling
      :meth:`~sagemaker.amazon.estimator.Framework.deploy` creates a hosted
      SageMaker endpoint and returns an
      :class:`~sagemaker.amazon.sklearn.model.SKLearnPredictor` instance that
      can be used to perform inference against the hosted model.
  
      Technical documentation on preparing Scikit-learn scripts for
      SageMaker training and using the Scikit-learn Estimator is available on
      the project home-page: https://github.com/aws/sagemaker-python-sdk
  
      Args:
          entry_point (str or PipelineVariable): Path (absolute or relative) to the Python source
              file which should be executed as the entry point to training.
              If ``source_dir`` is specified, then ``entry_point``
              must point to a file located at the root of ``source_dir``.
          framework_version (str): Scikit-learn version you want to use for
              executing your model training code. Defaults to ``None``. Required
              unless ``image_uri`` is provided. List of supported versions:
              https://docs.aws.amazon.com/sagemaker/latest/dg/sklearn.html
          py_version (str): Python version you want to use for executing your
              model training code (default: 'py3'). Currently, 'py3' is the only
              supported version. If ``None`` is passed in, ``image_uri`` must be
              provided.
          source_dir (str or PipelineVariable): Path (absolute, relative or an S3 URI) to
              a directory with any other training source code dependencies aside from the entry
              point file (default: None). If ``source_dir`` is an S3 URI, it must
              point to a tar.gz file. Structure within this directory are preserved
              when training on Amazon SageMaker.
          hyperparameters (dict[str, str] or dict[str, PipelineVariable]): Hyperparameters
              that will be used for training (default: None). The hyperparameters are made
              accessible as a dict[str, str] to the training code on
              SageMaker. For convenience, this accepts other types for keys
              and values, but ``str()`` will be called to convert them before
              training.
          image_uri (str or PipelineVariable)): If specified, the estimator will use this image
              for training and hosting, instead of selecting the appropriate
              SageMaker official image based on framework_version and
              py_version. It can be an ECR url or dockerhub image and tag.
  
              Examples:
                  123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
                  custom-image:latest.
  
              If ``framework_version`` or ``py_version`` are ``None``, then
              ``image_uri`` is required. If also ``None``, then a ``ValueError``
              will be raised.
          image_uri_region (str): If ``image_uri`` argument is None, the image uri
              associated with this object will be in this region.
              Default: region associated with SageMaker session.
          **kwargs: Additional kwargs passed to the
              :class:`~sagemaker.estimator.Framework` constructor.
  
      .. tip::
  
          You can find additional parameters for initializing this class at
          :class:`~sagemaker.estimator.Framework` and
          :class:`~sagemaker.estimator.EstimatorBase`.
      """
      instance_type = renamed_kwargs(
          "train_instance_type",
          "instance_type",
          kwargs.get("instance_type"),
          kwargs,
      )
      instance_count = renamed_kwargs(
          "train_instance_count",
          "instance_count",
          kwargs.get("instance_count"),
          kwargs,
      )
      validate_version_or_image_args(
          framework_version, py_version, image_uri
      )
      if py_version and py_version != "py3":
          raise AttributeError(
              "Scikit-learn image only supports Python 3. Please use 'py3' for py_version."
          )
      self.framework_version = framework_version
      self.py_version = py_version
  
      # SciKit-Learn does not support distributed training or training on GPU instance types.
      # Fail fast.
      _validate_not_gpu_instance_type(instance_type)
  
      if instance_count:
          instance_cnt_err_msg = (
              "Scikit-Learn does not support distributed training. Please remove the "
              "'instance_count' argument or set 'instance_count=1' when initializing SKLearn."
          )
          if is_pipeline_variable(instance_count):
              raise TypeError(
                  "Invalid type of instance_count (PipelineVariable - {}). ".format(
                      type(instance_count)
                  )
                  + instance_cnt_err_msg
              )
  
          if instance_count != 1:
              raise AttributeError(instance_cnt_err_msg)
  
      super(SKLearn, self).__init__(
          entry_point,
          source_dir,
          hyperparameters,
          image_uri=image_uri,
          **dict(kwargs, instance_count=1),
      )
  
      if image_uri is None:
          self.image_uri = image_uris.retrieve(
              SKLearn._framework_name,
              image_uri_region
              or self.sagemaker_session.boto_region_name,
              version=self.framework_version,
              py_version=self.py_version,
              instance_type=instance_type,
          )
  
file_path: sagemaker-python-sdk/src/sagemaker/sklearn/estimator.py
imports: from __future__ import absolute_import
  import logging
  from typing import Union, Optional, Dict
  from sagemaker import image_uris
  from sagemaker.deprecations import renamed_kwargs
  from sagemaker.estimator import Framework
  from sagemaker.fw_utils import framework_name_from_image, framework_version_from_tag, validate_version_or_image_args
  from sagemaker.sklearn import defaults
  from sagemaker.sklearn.model import SKLearnModel
  from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
  from sagemaker.workflow.entities import PipelineVariable
  from sagemaker.workflow import is_pipeline_variable
label_desc: Use image node_id 1 to create a new SKLearn object from inherited base classes: Framework with example: obj = SKLearn(entry_point, framework_version, py_version, source_dir, hyperparameters, image_uri, image_uri_region)