def __init__(self, entry_point, framework_version, source_dir=None, hyperparameters=None, py_version="py3", image_name=None, **kwargs): """ This ``Estimator`` executes an XGBoost based SageMaker Training Job. The managed XGBoost environment is an Amazon-built Docker container thatexecutes 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.xgboost.model.XGBoostPredictor` instance that can be used to perform inference against the hosted model. Technical documentation on preparing XGBoost scripts for SageMaker training and using the XGBoost Estimator is available on the project home-page: https://github.com/aws/sagemaker-python-sdk Args: entry_point (str): Path (absolute or relative) to the Python source file which should be executed as the entry point to training. This should be compatible with either Python 2.7 or Python 3.5. framework_version (str): XGBoost version you want to use for executing your model training code. List of supported versions https://github.com/aws/sagemaker-python-sdk#xgboost-sagemaker-estimators source_dir (str): Path (absolute or relative) to a directory with any other training source code dependencies aside from tne entry point file (default: None). Structure within this directory are preserved when training on Amazon SageMaker. hyperparameters (dict): 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. py_version (str): Python version you want to use for executing your model training code (default: 'py3'). One of 'py2' or 'py3'. image_name (str): 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. **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`. """ super(XGBoost, self).__init__(entry_point, source_dir, hyperparameters, image_name=image_name, **kwargs) if py_version == "py2": logger.warning(python_deprecation_warning(self.__framework_name__)) self.py_version = py_version if framework_version in XGBOOST_SUPPORTED_VERSIONS: self.framework_version = framework_version else: raise ValueError( get_unsupported_framework_version_error( self.__framework_name__, framework_version, XGBOOST_SUPPORTED_VERSIONS)) if image_name is None: self.image_name = get_xgboost_image_uri( self.sagemaker_session.boto_region_name, framework_version)
def __init__(self, entry_point, framework_version=defaults.SKLEARN_VERSION, source_dir=None, hyperparameters=None, py_version="py3", image_name=None, **kwargs): """This ``Estimator`` executes an Scikit-learn script in a managed Scikit-learn execution environment, 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): 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. source_dir (str): 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): 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. py_version (str): Python version you want to use for executing your model training code (default: 'py3'). One of 'py2' or 'py3'. image_name (str): 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. **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`. """ # SciKit-Learn does not support distributed training or training on GPU instance types. # Fail fast. train_instance_type = kwargs.get("train_instance_type") _validate_not_gpu_instance_type(train_instance_type) train_instance_count = kwargs.get("train_instance_count") if train_instance_count: if train_instance_count != 1: raise AttributeError( "Scikit-Learn does not support distributed training. " "Please remove the 'train_instance_count' argument or set " "'train_instance_count=1' when initializing SKLearn.") super(SKLearn, self).__init__(entry_point, source_dir, hyperparameters, image_name=image_name, **dict(kwargs, train_instance_count=1)) if py_version == "py2": logger.warning( python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION)) self.py_version = py_version if framework_version in defaults.SKLEARN_SUPPORTED_VERSIONS: self.framework_version = framework_version else: raise ValueError( get_unsupported_framework_version_error( self.__framework_name__, framework_version, defaults.SKLEARN_SUPPORTED_VERSIONS)) if framework_version != defaults.SKLEARN_LATEST_VERSION: logger.warning( later_framework_version_warning( defaults.SKLEARN_LATEST_VERSION)) if image_name is None: image_tag = "{}-{}-{}".format(framework_version, "cpu", py_version) self.image_name = default_framework_uri( SKLearn.__framework_name__, self.sagemaker_session.boto_region_name, image_tag)