class_docstr: An index-based algorithm. It uses a non-parametric method for classification or regression.
  
  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.
class_docstr_tok: ["An","index-based","algorithm",".","It","uses","a","non-parametric","method","for","classification","or","regression",".","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","."]
docstr: 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
  
  Args:
      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 or PipelineVariable): Number of Amazon EC2 instances to use
          for training.
      instance_type (str or PipelineVariable): 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".
      **kwargs: base class keyword argument values.
  
  .. tip::
  
      You can find additional parameters for initializing this class at
      :class:`~sagemaker.estimator.amazon_estimator.AmazonAlgorithmEstimatorBase` and
      :class:`~sagemaker.estimator.EstimatorBase`.
docstr_tok: ["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","Args",":","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","or","PipelineVariable",")",":","Number","of","Amazon","EC2","instances","to","use","for","training",".","instance_type","(","str","or","PipelineVariable",")",":","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","''",".","*","*","kwargs",":","base","class","keyword","argument","values",".","..","tip",":",":","You","can","find","additional","parameters","for","initializing","this","class","at",":","class",":","`","~sagemaker.estimator.amazon_estimator.AmazonAlgorithmEstimatorBase","`","and",":","class",":","`","~sagemaker.estimator.EstimatorBase","`","."]
code: def __init__(
      self,
      role: Optional[Union[str, PipelineVariable]] = None,
      instance_count: Optional[Union[int, PipelineVariable]] = None,
      instance_type: Optional[Union[str, PipelineVariable]] = None,
      k: Optional[int] = None,
      sample_size: Optional[int] = None,
      predictor_type: Optional[str] = None,
      dimension_reduction_type: Optional[str] = None,
      dimension_reduction_target: Optional[int] = None,
      index_type: Optional[str] = None,
      index_metric: Optional[str] = None,
      faiss_index_ivf_nlists: Optional[str] = None,
      faiss_index_pq_m: Optional[int] = None,
      **kwargs,
  ):
      """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
  
      Args:
          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 or PipelineVariable): Number of Amazon EC2 instances to use
              for training.
          instance_type (str or PipelineVariable): 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".
          **kwargs: base class keyword argument values.
  
      .. tip::
  
          You can find additional parameters for initializing this class at
          :class:`~sagemaker.estimator.amazon_estimator.AmazonAlgorithmEstimatorBase` and
          :class:`~sagemaker.estimator.EstimatorBase`.
      """
  
      super(KNN, self).__init__(
          role, instance_count, instance_type, **kwargs
      )
      self.k = k
      self.sample_size = sample_size
      self.predictor_type = predictor_type
      self.dimension_reduction_type = dimension_reduction_type
      self.dimension_reduction_target = dimension_reduction_target
      self.index_type = index_type
      self.index_metric = index_metric
      self.faiss_index_ivf_nlists = faiss_index_ivf_nlists
      self.faiss_index_pq_m = faiss_index_pq_m
      if dimension_reduction_type and not dimension_reduction_target:
          raise ValueError(
              '"dimension_reduction_target" is required when "dimension_reduction_type" is set.'
          )
  
imports: from __future__ import absolute_import
  from typing import Union, Optional
  from sagemaker import image_uris
  from sagemaker.amazon.amazon_estimator import AmazonAlgorithmEstimatorBase
  from sagemaker.amazon.common import RecordSerializer, RecordDeserializer
  from sagemaker.amazon.hyperparameter import Hyperparameter
  from sagemaker.amazon.validation import ge, isin
  from sagemaker.predictor import Predictor
  from sagemaker.model import Model
  from sagemaker.session import Session
  from sagemaker.utils import pop_out_unused_kwarg
  from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
  from sagemaker.workflow.entities import PipelineVariable
label_desc: Use image node_id 1 to create a new KNN object from inherited base classes: AmazonAlgorithmEstimatorBase with example: obj = KNN(role, instance_count, instance_type, k, sample_size, predictor_type, dimension_reduction_type, dimension_reduction_target, index_type, index_metric, faiss_index_ivf_nlists, faiss_index_pq_m)