Record Class ClusteringModel
java.lang.Object
java.lang.Record
smile.model.ClusteringModel
- Record Components:
algorithm- the clustering algorithm name.schema- the schema of input data (without response variable).formula- the feature selection formula.clustering- the fitted centroid clustering model.transform- optional feature preprocessing transform; may benull.- the model metadata tags.
- All Implemented Interfaces:
Serializable, Model
public record ClusteringModel(String algorithm, StructType schema, Formula formula, CentroidClustering<double[],double[]> clustering, Transform transform, Properties tags)
extends Record
implements Model, Serializable
The centroid-based clustering model.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionClusteringModel(String algorithm, StructType schema, Formula formula, CentroidClustering<double[], double[]> clustering, Properties tags) Constructs a clustering model without a preprocessing transform.ClusteringModel(String algorithm, StructType schema, Formula formula, CentroidClustering<double[], double[]> clustering, Transform transform, Properties tags) Creates an instance of aClusteringModelrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thealgorithmrecord component.double[]center(int i) Returns the centroid of the i-th cluster.double[][]centers()Returns the cluster centroids.CentroidClustering<double[], double[]> Returns the value of theclusteringrecord component.doubleReturns the total distortion (average within-cluster sum-of-squares).final booleanIndicates whether some other object is "equal to" this one.formula()Returns the value of theformularecord component.final inthashCode()Returns a hash code value for this object.Performs batch inference over a data frame.infer(DataFrame data, boolean probability, boolean explain, KernelSHAP.Options options) Performs batch inference over a data frame with customKernelSHAP.Options.Performs inference on a single tuple.infer(Tuple x, boolean probability, boolean explain, KernelSHAP.Options options) Performs inference on a single tuple with customKernelSHAP.Options.intk()Returns the number of clusters.int[]Predicts the cluster labels for a data frame.intPredicts the cluster label for a single observation.schema()Returns the value of theschemarecord component.tags()Returns the value of thetagsrecord component.final StringtoString()Returns a string representation of this record class.Returns the value of thetransformrecord component.
-
Constructor Details
-
ClusteringModel
public ClusteringModel(String algorithm, StructType schema, Formula formula, CentroidClustering<double[], double[]> clustering, Properties tags) Constructs a clustering model without a preprocessing transform.- Parameters:
algorithm- the clustering algorithm name.schema- the schema of input data (without response variable).formula- the feature selection formula.clustering- the fitted centroid clustering model.tags- the model metadata tags.
-
ClusteringModel
public ClusteringModel(String algorithm, StructType schema, Formula formula, CentroidClustering<double[], double[]> clustering, Transform transform, Properties tags) Creates an instance of aClusteringModelrecord class.- Parameters:
algorithm- the value for thealgorithmrecord componentschema- the value for theschemarecord componentformula- the value for theformularecord componentclustering- the value for theclusteringrecord componenttransform- the value for thetransformrecord componenttags- the value for thetagsrecord component
-
-
Method Details
-
predict
Predicts the cluster label for a single observation.- Parameters:
x- the input tuple.- Returns:
- the assigned cluster index.
-
predict
Predicts the cluster labels for a data frame.- Parameters:
data- the input data frame.- Returns:
- the assigned cluster indices.
-
k
public int k()Returns the number of clusters.- Returns:
- the number of clusters.
-
centers
public double[][] centers()Returns the cluster centroids.- Returns:
- the cluster centroids.
-
center
public double[] center(int i) Returns the centroid of the i-th cluster.- Parameters:
i- the cluster index.- Returns:
- the cluster centroid.
-
distortion
public double distortion()Returns the total distortion (average within-cluster sum-of-squares).- Returns:
- the distortion.
-
infer
Description copied from interface:ModelPerforms inference on a single tuple. -
infer
Description copied from interface:ModelPerforms inference on a single tuple with customKernelSHAP.Options. -
infer
Description copied from interface:ModelPerforms batch inference over a data frame. -
infer
public Prediction[] infer(DataFrame data, boolean probability, boolean explain, KernelSHAP.Options options) Description copied from interface:ModelPerforms batch inference over a data frame with customKernelSHAP.Options. -
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
algorithm
-
schema
Returns the value of theschemarecord component. -
formula
-
clustering
Returns the value of theclusteringrecord component.- Returns:
- the value of the
clusteringrecord component
-
transform
-
tags
Returns the value of thetagsrecord component.
-