Class KMeans

  • All Implemented Interfaces:
    java.io.Serializable

    public class KMeans
    extends java.lang.Object
    implements java.io.Serializable
    a model of the K Means Algorithm
    Author:
    Bhagat
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      KMeans​(int k)
      creates a K means model
      KMeans​(int k, int iterations)
      creates a K means model
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getIterations()  
      int getK()  
      private int[] minmax​(double[] arr)  
      double[] predict​(double[] input)
      predicts which cluster the input belongs to
      Vector predict​(Vector input)
      predicts which cluster the input belongs to
      void setIterations​(int iterations)  
      void train​(double[][] inputs)
      trains the model to find the clusters
      void train​(Matrix inputs)
      trains the model to find the clusters
      void train​(Vector[] inputs)
      trains the model to find the clusters
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • k

        private int k
        the number of clusters to find
      • clusters

        private Vector[] clusters
      • iterations

        private int iterations
        the number of iterations to run the algorithm
    • Constructor Detail

      • KMeans

        public KMeans​(int k,
                      int iterations)
        creates a K means model
        Parameters:
        k - the number of clusters
        iterations - the number of iterations to run the algorithm
      • KMeans

        public KMeans​(int k)
        creates a K means model
        Parameters:
        k - the number of clusters
    • Method Detail

      • minmax

        private int[] minmax​(double[] arr)
      • train

        public void train​(double[][] inputs)
        trains the model to find the clusters
        Parameters:
        inputs - the input data
      • train

        public void train​(Matrix inputs)
        trains the model to find the clusters
        Parameters:
        inputs - the input data
      • train

        public void train​(Vector[] inputs)
        trains the model to find the clusters
        Parameters:
        inputs - the input data
      • predict

        public double[] predict​(double[] input)
        predicts which cluster the input belongs to
        Parameters:
        input - the input array
        Returns:
        the mean array of the cluster
      • predict

        public Vector predict​(Vector input)
        predicts which cluster the input belongs to
        Parameters:
        input - the input vector
        Returns:
        the mean vector of the cluster
      • getIterations

        public int getIterations()
        Returns:
        the iterations
      • setIterations

        public void setIterations​(int iterations)
        Parameters:
        iterations - the iterations to set
      • getK

        public int getK()
        Returns:
        the k