Class KMeansModel

All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, org.apache.spark.ml.clustering.KMeansParams, Params, HasDistanceMeasure, HasFeaturesCol, HasMaxBlockSizeInMB, HasMaxIter, HasPredictionCol, HasSeed, HasSolver, HasTol, HasWeightCol, GeneralMLWritable, org.apache.spark.ml.util.HasTrainingSummary<KMeansSummary>, Identifiable, MLWritable

public class KMeansModel extends Model<KMeansModel> implements org.apache.spark.ml.clustering.KMeansParams, GeneralMLWritable, org.apache.spark.ml.util.HasTrainingSummary<KMeansSummary>
Model fitted by KMeans.

param: parentModel a model trained by spark.mllib.clustering.KMeans.

See Also:
  • Method Details

    • read

      public static MLReader<KMeansModel> read()
    • load

      public static KMeansModel load(String path)
    • k

      public final IntParam k()
      Specified by:
      k in interface org.apache.spark.ml.clustering.KMeansParams
    • initMode

      public final Param<String> initMode()
      Specified by:
      initMode in interface org.apache.spark.ml.clustering.KMeansParams
    • initSteps

      public final IntParam initSteps()
      Specified by:
      initSteps in interface org.apache.spark.ml.clustering.KMeansParams
    • solver

      public final Param<String> solver()
      Description copied from interface: HasSolver
      Param for the solver algorithm for optimization.
      Specified by:
      solver in interface HasSolver
      Specified by:
      solver in interface org.apache.spark.ml.clustering.KMeansParams
      Returns:
      (undocumented)
    • maxBlockSizeInMB

      public final DoubleParam maxBlockSizeInMB()
      Description copied from interface: HasMaxBlockSizeInMB
      Param for Maximum memory in MB for stacking input data into blocks. Data is stacked within partitions. If more than remaining data size in a partition then it is adjusted to the data size. Default 0.0 represents choosing optimal value, depends on specific algorithm. Must be &gt;= 0..
      Specified by:
      maxBlockSizeInMB in interface HasMaxBlockSizeInMB
      Returns:
      (undocumented)
    • weightCol

      public final Param<String> weightCol()
      Description copied from interface: HasWeightCol
      Param for weight column name. If this is not set or empty, we treat all instance weights as 1.0.
      Specified by:
      weightCol in interface HasWeightCol
      Returns:
      (undocumented)
    • distanceMeasure

      public final Param<String> distanceMeasure()
      Description copied from interface: HasDistanceMeasure
      Param for The distance measure. Supported options: 'euclidean' and 'cosine'.
      Specified by:
      distanceMeasure in interface HasDistanceMeasure
      Returns:
      (undocumented)
    • tol

      public final DoubleParam tol()
      Description copied from interface: HasTol
      Param for the convergence tolerance for iterative algorithms (&gt;= 0).
      Specified by:
      tol in interface HasTol
      Returns:
      (undocumented)
    • predictionCol

      public final Param<String> predictionCol()
      Description copied from interface: HasPredictionCol
      Param for prediction column name.
      Specified by:
      predictionCol in interface HasPredictionCol
      Returns:
      (undocumented)
    • seed

      public final LongParam seed()
      Description copied from interface: HasSeed
      Param for random seed.
      Specified by:
      seed in interface HasSeed
      Returns:
      (undocumented)
    • featuresCol

      public final Param<String> featuresCol()
      Description copied from interface: HasFeaturesCol
      Param for features column name.
      Specified by:
      featuresCol in interface HasFeaturesCol
      Returns:
      (undocumented)
    • maxIter

      public final IntParam maxIter()
      Description copied from interface: HasMaxIter
      Param for maximum number of iterations (&gt;= 0).
      Specified by:
      maxIter in interface HasMaxIter
      Returns:
      (undocumented)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
      Returns:
      (undocumented)
    • numFeatures

      public int numFeatures()
    • copy

      public KMeansModel copy(ParamMap extra)
      Description copied from interface: Params
      Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See defaultCopy().
      Specified by:
      copy in interface Params
      Specified by:
      copy in class Model<KMeansModel>
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)
    • setFeaturesCol

      public KMeansModel setFeaturesCol(String value)
    • setPredictionCol

      public KMeansModel setPredictionCol(String value)
    • transform

      public Dataset<Row> transform(Dataset<?> dataset)
      Description copied from class: Transformer
      Transforms the input dataset.
      Specified by:
      transform in class Transformer
      Parameters:
      dataset - (undocumented)
      Returns:
      (undocumented)
    • transformSchema

      public StructType transformSchema(StructType schema)
      Description copied from class: PipelineStage
      Check transform validity and derive the output schema from the input schema.

      We check validity for interactions between parameters during transformSchema and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled by Param.validate().

      Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.

      Specified by:
      transformSchema in class PipelineStage
      Parameters:
      schema - (undocumented)
      Returns:
      (undocumented)
    • predict

      public int predict(Vector features)
    • clusterCenters

      public Vector[] clusterCenters()
    • write

      public GeneralMLWriter write()
      Returns a GeneralMLWriter instance for this ML instance.

      For KMeansModel, this does NOT currently save the training summary(). An option to save summary() may be added in the future.

      Specified by:
      write in interface GeneralMLWritable
      Specified by:
      write in interface MLWritable
      Returns:
      (undocumented)
    • toString

      public String toString()
      Specified by:
      toString in interface Identifiable
      Overrides:
      toString in class Object
    • summary

      public KMeansSummary summary()
      Gets summary of model on training set. An exception is thrown if hasSummary is false.
      Specified by:
      summary in interface org.apache.spark.ml.util.HasTrainingSummary<KMeansSummary>
      Returns:
      (undocumented)