Class KNeighbors

java.lang.Object
ai.beestream.jitnn.ml.KNeighbors

public final class KNeighbors extends Object
k-nearest neighbours by brute force on the device (Euclidean distance, uniform weights), after scikit-learn's KNeighborsClassifier and KNeighborsRegressor. Class ties go to the smallest label.
  • Constructor Details

    • KNeighbors

      public KNeighbors(int k)
      Neighbours by the k nearest training samples.
  • Method Details

    • fit

      public KNeighbors fit(Tensor x, int[] y)
      Classification: integer labels.
    • fit

      public KNeighbors fit(Tensor x, Tensor y)
      Regression: targets [n] or [n, t].
    • kneighbors

      public Tensor kneighbors(Tensor q)
      INT32 indices [m, k] of the k nearest training rows of each query row.
    • predict

      public int[] predict(Tensor q)
      The majority label of each query's neighbours (a classifier's fit only).
    • predictProba

      public Tensor predictProba(Tensor q)
      Class probabilities [m, c]: the fraction of neighbours per class.
    • predictValues

      public Tensor predictValues(Tensor q)
      Regression predictions [m, t].