StreamingKMeans

class pyspark.mllib.clustering.StreamingKMeans(k=2, decayFactor=1.0, timeUnit='batches')[source]

Provides methods to set k, decayFactor, timeUnit to configure the KMeans algorithm for fitting and predicting on incoming dstreams. More details on how the centroids are updated are provided under the docs of StreamingKMeansModel.

New in version 1.5.0.

Parameters
kint, optional

Number of clusters. (default: 2)

decayFactorfloat, optional

Forgetfulness of the previous centroids. (default: 1.0)

timeUnitstr, optional

Can be “batches” or “points”. If points, then the decay factor is raised to the power of number of new points and if batches, then decay factor will be used as is. (default: “batches”)

Methods

latestModel()

Return the latest model

predictOn(dstream)

Make predictions on a dstream.

predictOnValues(dstream)

Make predictions on a keyed dstream.

setDecayFactor(decayFactor)

Set decay factor.

setHalfLife(halfLife, timeUnit)

Set number of batches after which the centroids of that particular batch has half the weightage.

setInitialCenters(centers, weights)

Set initial centers.

setK(k)

Set number of clusters.

setRandomCenters(dim, weight, seed)

Set the initial centers to be random samples from a gaussian population with constant weights.

trainOn(dstream)

Train the model on the incoming dstream.

Methods Documentation

latestModel()[source]

Return the latest model

New in version 1.5.0.

predictOn(dstream)[source]

Make predictions on a dstream. Returns a transformed dstream object

New in version 1.5.0.

predictOnValues(dstream)[source]

Make predictions on a keyed dstream. Returns a transformed dstream object.

New in version 1.5.0.

setDecayFactor(decayFactor)[source]

Set decay factor.

New in version 1.5.0.

setHalfLife(halfLife, timeUnit)[source]

Set number of batches after which the centroids of that particular batch has half the weightage.

New in version 1.5.0.

setInitialCenters(centers, weights)[source]

Set initial centers. Should be set before calling trainOn.

New in version 1.5.0.

setK(k)[source]

Set number of clusters.

New in version 1.5.0.

setRandomCenters(dim, weight, seed)[source]

Set the initial centers to be random samples from a gaussian population with constant weights.

New in version 1.5.0.

trainOn(dstream)[source]

Train the model on the incoming dstream.

New in version 1.5.0.