Scikit Learn Estimator¶
SKLearn(entry_point, framework_version='0.20.0', source_dir=None, hyperparameters=None, py_version='py3', image_name=None, **kwargs)¶
Handle end-to-end training and deployment of custom Scikit-learn code.
Estimatorexecutes 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
Training is started by calling
fit()on this Estimator. After training is complete, calling
deploy()creates a hosted SageMaker endpoint and returns an
SKLearnPredictorinstance 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
- 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) – Scikit-learn version you want to use for executing your model training code. List of supported versions https://github.com/aws/sagemaker-python-sdk#sklearn-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: ‘py2’). 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. .. rubric:: Examples
- **kwargs – Additional kwargs passed to the
create_model(model_server_workers=None, role=None, vpc_config_override='VPC_CONFIG_DEFAULT', **kwargs)¶
Create a SageMaker
SKLearnModelobject that can be deployed to an
- model_server_workers (int) – Optional. The number of worker processes used by the inference server. If None, server will use one worker per vCPU.
- role (str) – The
ExecutionRoleArnIAM Role ARN for the
Model, which is also used during transform jobs. If not specified, the role from the Estimator will be used.
- vpc_config_override (dict[str, list[str]]) – Optional override for VpcConfig set on the model. Default: use subnets and security groups from this Estimator. * ‘Subnets’ (list[str]): List of subnet ids. * ‘SecurityGroupIds’ (list[str]): List of security group ids.
- **kwargs – Passed to initialization of
SKLearnModel()for full details.
Scikit Learn Model¶
SKLearnModel(model_data, role, entry_point, image=None, py_version='py3', framework_version='0.20.0', predictor_cls=<class 'sagemaker.sklearn.model.SKLearnPredictor'>, model_server_workers=None, **kwargs)¶
An Scikit-learn SageMaker
Modelthat can be deployed to a SageMaker
Initialize an SKLearnModel.
- model_data (str) – The S3 location of a SageMaker model data
- role (str) – An AWS IAM role (either name or full ARN). The Amazon SageMaker training jobs and APIs that create Amazon SageMaker endpoints use this role to access training data and model artifacts. After the endpoint is created, the inference code might use the IAM role, if it needs to access an AWS resource.
- entry_point (str) – Path (absolute or relative) to the Python source file which should be executed as the entry point to model hosting. This should be compatible with either Python 2.7 or Python 3.5.
- image (str) – A Docker image URI (default: None). If not specified, a default image for Scikit-learn will be used.
- py_version (str) – Python version you want to use for executing your model training code (default: ‘py2’).
- framework_version (str) – Scikit-learn version you want to use for executing your model training code.
- predictor_cls (callable[str, sagemaker.session.Session]) – A function
to call to create a predictor with an endpoint name and
Session. If specified,
deploy()returns the result of invoking this function on the created endpoint name.
- **kwargs – Keyword arguments passed to the
Return a container definition with framework configuration set in model environment variables.
- instance_type (str) – The EC2 instance type to deploy this Model to. For example, ‘ml.p2.xlarge’.
- accelerator_type (str) – The Elastic Inference accelerator type to deploy to the instance for loading and making inferences to the model. For example, ‘ml.eia1.medium’. Note: accelerator types are not supported by SKLearnModel.
A container definition object usable with the CreateModel API.
Create a URI for the serving image.
The appropriate image URI based on the given parameters.
- model_data (str) – The S3 location of a SageMaker model data
Scikit Learn Predictor¶
A RealTimePredictor for inference against Scikit-learn Endpoints.
This is able to serialize Python lists, dictionaries, and numpy arrays to multidimensional tensors for Scikit-learn inference.
- endpoint_name (str) – The name of the endpoint to perform inference on.
- sagemaker_session (sagemaker.session.Session) – Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, the estimator creates one using the default AWS configuration chain.
Scikit Learn Processor¶
SKLearnProcessor(framework_version, role, instance_type, instance_count, command=None, volume_size_in_gb=30, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, base_job_name=None, sagemaker_session=None, env=None, tags=None, network_config=None)¶
Handles Amazon SageMaker processing tasks for jobs using scikit-learn.
SKLearnProcessorinstance. The SKLearnProcessor handles Amazon SageMaker processing tasks for jobs using scikit-learn.
- framework_version (str) – The version of scikit-learn.
- role (str) – An AWS IAM role name or ARN. The Amazon SageMaker training jobs and APIs that create Amazon SageMaker endpoints use this role to access training data and model artifacts. After the endpoint is created, the inference code might use the IAM role, if it needs to access an AWS resource.
- instance_type (str) – Type of EC2 instance to use for processing, for example, ‘ml.c4.xlarge’.
- instance_count (int) – The number of instances to run the Processing job with. Defaults to 1.
- command ([str]) – The command to run, along with any command-line flags. Example: [“python3”, “-v”]. If not provided, [“python3”] or [“python2”] will be chosen based on the py_version parameter.
- volume_size_in_gb (int) – Size in GB of the EBS volume to use for storing data during processing (default: 30).
- volume_kms_key (str) – A KMS key for the processing volume.
- output_kms_key (str) – The KMS key id for all ProcessingOutputs.
- max_runtime_in_seconds (int) – Timeout in seconds. After this amount of time Amazon SageMaker terminates the job regardless of its current status.
- base_job_name (str) – Prefix for processing name. If not specified, the processor generates a default job name, based on the training image name and current timestamp.
- sagemaker_session (sagemaker.session.Session) – Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, the processor creates one using the default AWS configuration chain.
- env (dict) – Environment variables to be passed to the processing job.
- tags ([dict]) – List of tags to be passed to the processing job.
- network_config (sagemaker.network.NetworkConfig) – A NetworkConfig object that configures network isolation, encryption of inter-container traffic, security group IDs, and subnets.