Class KMeans

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

public final class KMeans extends Object
k-means clustering with Lloyd's algorithm, after scikit-learn's KMeans: k-means++ seeding (or given initial centres), nInit restarts keeping the lowest inertia, and stopping when the assignments no longer change or the centres move less than tol times the mean feature variance.
  • Constructor Summary

    Constructors
    Constructor
    Description
    KMeans(int k, int maxIter, float tol, int nInit, long seed)
    k-means with k clusters, at most maxIter iterations per run, tolerance tol, nInit runs, seeding from seed.
    KMeans(int k, long seed)
    k-means with scikit-learn's defaults: 300 iterations, tolerance 1e-4, one run.
  • Method Summary

    Modifier and Type
    Method
    Description
    The cluster centres [k, features].
    Fits from k-means++ seeds.
    fit(Tensor x, Tensor init)
    Fits from the given initial centres [k, d].
    float
    Sum of squared distances of the training samples to their nearest centre.
    int
    The iterations the kept run took.
    int[]
    Index of the nearest centre of each row.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KMeans

      public KMeans(int k, int maxIter, float tol, int nInit, long seed)
      k-means with k clusters, at most maxIter iterations per run, tolerance tol, nInit runs, seeding from seed.
    • KMeans

      public KMeans(int k, long seed)
      k-means with scikit-learn's defaults: 300 iterations, tolerance 1e-4, one run.
  • Method Details

    • fit

      public KMeans fit(Tensor x)
      Fits from k-means++ seeds.
    • fit

      public KMeans fit(Tensor x, Tensor init)
      Fits from the given initial centres [k, d].
    • predict

      public int[] predict(Tensor x)
      Index of the nearest centre of each row.
    • centres

      public Tensor centres()
      The cluster centres [k, features].
    • inertia

      public float inertia()
      Sum of squared distances of the training samples to their nearest centre.
    • iterations

      public int iterations()
      The iterations the kept run took.