KNN | R Documentation |
For classification problems, the algorithm queries the k points that are closest to the sample point and returns the most frequently used label of their class as the predicted label. For regression problems, the algorithm queries the k closest points to the sample point and returns the average of their feature values as the predicted value.
sagemaker.mlcore::EstimatorBase
-> sagemaker.mlcore::AmazonAlgorithmEstimatorBase
-> KNN
repo_name
sagemaker repo name for framework
repo_version
version of framework
.module
mimic python module
k
Number of nearest neighbors.
sample_size
Number of data points to be sampled from the training data set
predictor_type
Type of inference to use on the data's labels
dimension_reduction_target
Target dimension to reduce to
dimension_reduction_type
Type of dimension reduction technique to use
index_metric
Distance metric to measure between points when finding nearest neighbors
index_type
Type of index to use. Valid values are "faiss.Flat", "faiss.IVFFlat", "faiss.IVFPQ".
faiss_index_ivf_nlists
Number of centroids to construct in the index
faiss_index_pq_m
Number of vector sub-components to construct in the index
sagemaker.mlcore::EstimatorBase$latest_job_debugger_artifacts_path()
sagemaker.mlcore::EstimatorBase$latest_job_profiler_artifacts_path()
sagemaker.mlcore::EstimatorBase$latest_job_tensorboard_artifacts_path()
sagemaker.mlcore::AmazonAlgorithmEstimatorBase$hyperparameters()
sagemaker.mlcore::AmazonAlgorithmEstimatorBase$prepare_workflow_for_training()
sagemaker.mlcore::AmazonAlgorithmEstimatorBase$training_image_uri()
new()
k-nearest neighbors (KNN) is :class:'Estimator' used for classification and regression. This Estimator may be fit via calls to :meth:'~sagemaker.amazon.amazon_estimator.AmazonAlgorithmEstimatorBase.fit'. It requires Amazon :class:'~sagemaker.amazon.record_pb2.Record' protobuf serialized data to be stored in S3. There is an utility :meth:'~sagemaker.amazon.amazon_estimator.AmazonAlgorithmEstimatorBase.record_set' that can be used to upload data to S3 and creates :class:'~sagemaker.amazon.amazon_estimator.RecordSet' to be passed to the 'fit' call. To learn more about the Amazon protobuf Record class and how to prepare bulk data in this format, please consult AWS technical documentation: https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-training.html After this Estimator is fit, model data is stored in S3. The model may be deployed to an Amazon SageMaker Endpoint by invoking :meth:'~sagemaker.amazon.estimator.EstimatorBase.deploy'. As well as deploying an Endpoint, deploy returns a :class:'~sagemaker.amazon.knn.KNNPredictor' object that can be used for inference calls using the trained model hosted in the SageMaker Endpoint. KNN Estimators can be configured by setting hyperparameters. The available hyperparameters for KNN are documented below. For further information on the AWS KNN algorithm, please consult AWS technical documentation: https://docs.aws.amazon.com/sagemaker/latest/dg/knn.html
KNN$new( role, instance_count, instance_type, k, sample_size, predictor_type, dimension_reduction_type = NULL, dimension_reduction_target = NULL, index_type = NULL, index_metric = NULL, faiss_index_ivf_nlists = NULL, faiss_index_pq_m = NULL, ... )
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 accessing AWS resource.
instance_count
(int): Number of Amazon EC2 instances to use for training.
instance_type
(str): Type of EC2 instance to use for training, for example, 'ml.c4.xlarge'.
k
(int): Required. Number of nearest neighbors.
sample_size
(int): Required. Number of data points to be sampled from the training data set.
predictor_type
(str): Required. Type of inference to use on the data's labels, allowed values are 'classifier' and 'regressor'.
dimension_reduction_type
(str): Optional. Type of dimension reduction technique to use. Valid values: "sign", "fjlt"
dimension_reduction_target
(int): Optional. Target dimension to reduce to. Required when dimension_reduction_type is specified.
index_type
(str): Optional. Type of index to use. Valid values are "faiss.Flat", "faiss.IVFFlat", "faiss.IVFPQ".
index_metric
(str): Optional. Distance metric to measure between points when finding nearest neighbors. Valid values are "COSINE", "INNER_PRODUCT", "L2"
faiss_index_ivf_nlists
(str): Optional. Number of centroids to construct in the index if index_type is "faiss.IVFFlat" or "faiss.IVFPQ".
faiss_index_pq_m
(int): Optional. Number of vector sub-components to construct in the index, if index_type is "faiss.IVFPQ".
...
: base class keyword argument values.
create_model()
Return a :class:'~sagemaker.amazon.KNNModel' referencing the latest s3 model data produced by this Estimator.
KNN$create_model(vpc_config_override = "VPC_CONFIG_DEFAULT", ...)
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.
...
: Additional kwargs passed to the KNNModel constructor.
.prepare_for_training()
Set hyperparameters needed for training. This method will also validate “source_dir“.
KNN$.prepare_for_training(records, mini_batch_size = NULL, job_name = NULL)
records
(RecordSet) – The records to train this Estimator on.
mini_batch_size
(int or None) – The size of each mini-batch to use when training. If None, a default value will be used.
job_name
(str): Name of the training job to be created. If not specified, one is generated, using the base name given to the constructor if applicable.
clone()
The objects of this class are cloneable with this method.
KNN$clone(deep = FALSE)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.