jsat.clustering.kmeans
Class KMeans
- java.lang.Object
-
- jsat.clustering.ClustererBase
-
- jsat.clustering.KClustererBase
-
- jsat.clustering.kmeans.KMeans
-
- All Implemented Interfaces:
- java.io.Serializable, Clusterer, KClusterer, Parameterized
- Direct Known Subclasses:
- ElkanKMeans, GMeans, HamerlyKMeans, KMeansPDN, NaiveKMeans, XMeans
public abstract class KMeans extends KClustererBase implements Parameterized
Base class for the numerous implementations of k-means that exist. This base class provides an slow heuristic approach to the selection of k.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static SeedSelectionMethods.SeedSelectionDEFAULT_SEED_SELECTIONThis is the default seed selection method used in ElkanKMeans.
-
Constructor Summary
Constructors Constructor and Description KMeans(DistanceMetric dm, SeedSelectionMethods.SeedSelection seedSelection, java.util.Random rand)KMeans(KMeans toCopy)Copy constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract KMeansclone()int[]cluster(DataSet dataSet, boolean parallel, int[] designations)Performs clustering on the given data set.int[]cluster(DataSet dataSet, int[] designations)Performs clustering on the given data set.int[]cluster(DataSet dataSet, int clusters, boolean parallel, int[] designations)int[]cluster(DataSet dataSet, int lowK, int highK, boolean parallel, int[] designations)DistanceMetricgetDistanceMetric()Returns the distance metric in useintgetIterationLimit()Returns the maximum number of iterations of the ElkanKMeans algorithm that will be performed.java.util.List<Vec>getMeans()Returns the raw list of means that were used for each class.SeedSelectionMethods.SeedSelectiongetSeedSelection()voidsetIterationLimit(int iterLimit)Sets the maximum number of iterations allowedvoidsetSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)Sets the method of seed selection to use for this algorithm.voidsetStoreMeans(boolean storeMeans)If set totruethe computed means will be stored after clustering is completed, and can then be retrieved usinggetMeans().booleansupportsWeightedData()Indicates whether the model knows how to cluster using weighted data points.-
Methods inherited from class jsat.clustering.ClustererBase
createClusterListFromAssignmentArray, getDatapointsFromCluster
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Field Detail
-
DEFAULT_SEED_SELECTION
public static final SeedSelectionMethods.SeedSelection DEFAULT_SEED_SELECTION
This is the default seed selection method used in ElkanKMeans. When used with theEuclideanDistance, it selects seeds that are log optimal with a high probability.
-
-
Constructor Detail
-
KMeans
public KMeans(DistanceMetric dm, SeedSelectionMethods.SeedSelection seedSelection, java.util.Random rand)
-
KMeans
public KMeans(KMeans toCopy)
Copy constructor- Parameters:
toCopy-
-
-
Method Detail
-
setIterationLimit
public void setIterationLimit(int iterLimit)
Sets the maximum number of iterations allowed- Parameters:
iterLimit- the maximum number of iterations of the ElkanKMeans algorithm
-
getIterationLimit
public int getIterationLimit()
Returns the maximum number of iterations of the ElkanKMeans algorithm that will be performed.- Returns:
- the maximum number of iterations of the ElkanKMeans algorithm that will be performed.
-
setStoreMeans
public void setStoreMeans(boolean storeMeans)
If set totruethe computed means will be stored after clustering is completed, and can then be retrieved usinggetMeans().- Parameters:
storeMeans-trueif the means should be stored for later,falseto discard them once clustering is complete.
-
getMeans
public java.util.List<Vec> getMeans()
Returns the raw list of means that were used for each class.- Returns:
- the list of means for each class
-
setSeedSelection
public void setSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)
Sets the method of seed selection to use for this algorithm.SeedSelectionMethods.SeedSelection.KPPis recommended for this algorithm in particular.- Parameters:
seedSelection- the method of seed selection to use
-
getSeedSelection
public SeedSelectionMethods.SeedSelection getSeedSelection()
- Returns:
- the method of seed selection used
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
Returns the distance metric in use- Returns:
- the distance metric in use
-
cluster
public int[] cluster(DataSet dataSet, int[] designations)
Description copied from interface:ClustererPerforms clustering on the given data set. Parameters may be estimated by the method, or other heuristics performed.- Specified by:
clusterin interfaceClusterer- Parameters:
dataSet- the data set to perform clustering ondesignations- the array which will contain the designated values. The array will be altered and returned by the function. If null is given, a new array will be created and returned.- Returns:
- an array indicating for each value indicating the cluster designation. This is the same array as designations, or a new one if the input array was null
-
cluster
public int[] cluster(DataSet dataSet, boolean parallel, int[] designations)
Description copied from interface:ClustererPerforms clustering on the given data set. Parameters may be estimated by the method, or other heuristics performed.- Specified by:
clusterin interfaceClusterer- Parameters:
dataSet- the data set to perform clustering onparallel-trueif multiple threads should be used to perform clustering.falseif it should be done in a single threaded manner.designations- the array which will contain the designated values. The array will be altered and returned by the function. If null is given, a new array will be created and returned.- Returns:
- the int[]
-
cluster
public int[] cluster(DataSet dataSet, int clusters, boolean parallel, int[] designations)
- Specified by:
clusterin interfaceKClusterer
-
cluster
public int[] cluster(DataSet dataSet, int lowK, int highK, boolean parallel, int[] designations)
- Specified by:
clusterin interfaceKClusterer
-
clone
public abstract KMeans clone()
- Specified by:
clonein interfaceClusterer- Specified by:
clonein interfaceKClusterer- Specified by:
clonein classKClustererBase
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClustererIndicates whether the model knows how to cluster using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClusterer- Returns:
- true if the model supports weighted data, false otherwise
-
-
DataMelt 3.0 © DataMelt by jWork.ORG