ca.pfv.spmf.algorithms.clustering.kmeans
Class AlgoKMeans
- java.lang.Object
-
- ca.pfv.spmf.algorithms.clustering.kmeans.AlgoKMeans
-
public class AlgoKMeans extends java.lang.ObjectAn implementation of the K-means algorithm (J. MacQueen, 1967).
The K-means algorithm steps are (text from Wikipedia) : 1) Choose the number of clusters, k. * 2) Randomly generate k clusters and determine the cluster centers, or directly generate k random points as cluster centers. 3) Assign each point to the nearest cluster center. 4) Recompute the new cluster centers. 5) Repeat the two previous steps until some convergence criterion is met (usually that the assignment hasn't changed).
-
-
Constructor Summary
Constructors Constructor and Description AlgoKMeans()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidprintStatistics()Print statistics of the latest execution to System.out.java.util.List<Cluster>runAlgorithm(java.lang.String inputFile, int k)Run the K-Means algorithmvoidsaveToFile(java.lang.String output)Save the clusters to an output file
-
-
-
Method Detail
-
runAlgorithm
public java.util.List<Cluster> runAlgorithm(java.lang.String inputFile, int k) throws java.lang.NumberFormatException, java.io.IOException
Run the K-Means algorithm- Parameters:
inputFile- an input file path containing a list of vectors of double valuesk- the parameter k- Returns:
- a list of clusters (some of them may be empty)
- Throws:
java.io.IOException- exception if an error while writing the file occursjava.lang.NumberFormatException
-
printStatistics
public void printStatistics()
Print statistics of the latest execution to System.out.
-
saveToFile
public void saveToFile(java.lang.String output) throws java.io.IOExceptionSave the clusters to an output file- Parameters:
output- the output file path- Throws:
java.io.IOException- exception if there is some writing error.
-
-
DMelt 3.0 © DataMelt by jWork.ORG