Package io.bhagat.ai.unsupervised
Class KMeans
- java.lang.Object
-
- io.bhagat.ai.unsupervised.KMeans
-
- All Implemented Interfaces:
java.io.Serializable
public class KMeans extends java.lang.Object implements java.io.Serializablea model of the K Means Algorithm- Author:
- Bhagat
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private Vector[]clustersstatic intDEFAULT_ITERATIONSprivate intiterationsthe number of iterations to run the algorithmprivate intkthe number of clusters to findprivate static longserialVersionUID
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetIterations()intgetK()private int[]minmax(double[] arr)double[]predict(double[] input)predicts which cluster the input belongs toVectorpredict(Vector input)predicts which cluster the input belongs tovoidsetIterations(int iterations)voidtrain(double[][] inputs)trains the model to find the clustersvoidtrain(Matrix inputs)trains the model to find the clustersvoidtrain(Vector[] inputs)trains the model to find the clusters
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
DEFAULT_ITERATIONS
public static final int DEFAULT_ITERATIONS
- See Also:
- Constant Field Values
-
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
-
-
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
-
-