code: def __init__(
      self,
      logical_operator,
      train_data,
      train_labels,
      n_neighbors,
      weights,
      classes,
      batch_size,
      is_classifier,
      metric_type,
      metric_params,
  ):
      super(KNeighborsModel, self).__init__(logical_operator)
      self.classification = is_classifier
      self.regression = not is_classifier
      self.train_data = torch.nn.Parameter(
          torch.from_numpy(train_data.astype("float32")),
          requires_grad=False,
      )
      self.train_labels = torch.nn.Parameter(
          torch.from_numpy(train_labels.astype("int64")),
          requires_grad=False,
      )
      self.n_neighbors = n_neighbors
      self.metric_type = metric_type
  
      if self.metric_type == MetricType.minkowski:
          self.p = float(metric_params["p"])
      elif self.metric_type == MetricType.wminkowski:
          self.p = float(metric_params["p"])
          self.w = torch.nn.Parameter(
              torch.from_numpy(
                  metric_params["w"].astype("float32").reshape(1, -1)
              ),
              requires_grad=False,
          )
          self.train_data = torch.nn.Parameter(
              torch.from_numpy(
                  metric_params["w"].astype("float32").reshape(1, -1)
                  * train_data.astype("float32")
              ),
              requires_grad=False,
          )
      elif self.metric_type == MetricType.seuclidean:
          self.V = torch.nn.Parameter(
              torch.from_numpy(
                  np.power(
                      metric_params["V"]
                      .astype("float32")
                      .reshape(1, -1),
                      -0.5,
                  )
              ),
              requires_grad=False,
          )
          self.train_data = torch.nn.Parameter(
              torch.from_numpy(
                  np.power(
                      metric_params["V"]
                      .astype("float32")
                      .reshape(1, -1),
                      -0.5,
                  )
                  * train_data.astype("float32")
              ),
              requires_grad=False,
          )
      elif self.metric_type == MetricType.mahalanobis:
          cholesky_l = np.linalg.cholesky(metric_params["VI"]).astype(
              "float32"
          )
          self.L = torch.nn.Parameter(
              torch.from_numpy(cholesky_l), requires_grad=False
          )
          self.train_data = torch.nn.Parameter(
              torch.from_numpy(
                  np.matmul(train_data.astype("float32"), cholesky_l)
              ),
              requires_grad=False,
          )
  
      if is_classifier:
          # classification
          self.train_labels = torch.nn.Parameter(
              torch.from_numpy(train_labels.astype("int64")),
              requires_grad=False,
          )
          self.classes = torch.nn.Parameter(
              torch.IntTensor(classes), requires_grad=False
          )
          self.n_classes = len(classes)
          self.perform_class_select = False
  
          if min(classes) != 0 or max(classes) != len(classes) - 1:
              self.perform_class_select = True
          self.one_tensor = torch.FloatTensor([1.0])
          self.proba_tensor = torch.zeros(
              (batch_size, self.n_classes), dtype=torch.float32
          )
      else:
          # regression
          self.train_labels = torch.nn.Parameter(
              torch.from_numpy(train_labels.astype("float32")),
              requires_grad=False,
          )
          self.n_targets = 1
          if len(self.train_labels.shape) == 2:
              self.n_targets = self.train_labels.shape[1]
  
      self.weights = weights
  
file_path: hummingbird/hummingbird/ml/operator_converters/_kneighbors_implementations.py
imports: from enum import Enum
  import torch
  import numpy
  from ._physical_operator import PhysicalOperator
label_desc: Use image node_id 1 to create a new KNeighborsModel object from inherited base classes: PhysicalOperator, torch.nn with example: obj = KNeighborsModel(logical_operator, train_data, train_labels, n_neighbors, weights, classes, batch_size, is_classifier, metric_type, metric_params)