KMeansModel#

class spark_rapids_ml.clustering.KMeansModel(cluster_centers_: List[List[float]], n_cols: int, dtype: str)#

KMeans gpu model for clustering input vectors to learned k centers. Refer to the KMeans class for learning the k centers.

Methods

clear(param)

Reset a Spark ML Param to its default value, setting matching cuML parameter, if exists.

clusterCenters()

Returns the list of cluster centers.

copy([extra])

cpu()

Return the PySpark ML KMeansModel

explainParam(param)

Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.

explainParams()

Returns the documentation of all params with their optionally default values and user-supplied values.

extractParamMap([extra])

Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.

getFeaturesCol()

Gets the value of featuresCol or featuresCols

getFeaturesCols()

Gets the value of featuresCols or its default value.

getInitMode()

Gets the value of initMode

getK()

Gets the value of k

getMaxIter()

Gets the value of maxIter or its default value.

getOrDefault(param)

Gets the value of a param in the user-supplied param map or its default value.

getParam(paramName)

Gets a param by its name.

getPredictionCol()

Gets the value of predictionCol or its default value.

getSeed()

Gets the value of seed or its default value.

getTol()

Gets the value of tol or its default value.

hasDefault(param)

Checks whether a param has a default value.

hasParam(paramName)

Tests whether this instance contains a param with a given (string) name.

isDefined(param)

Checks whether a param is explicitly set by user or has a default value.

isSet(param)

Checks whether a param is explicitly set by user.

load(path)

Reads an ML instance from the input path, a shortcut of read().load(path).

predict(value)

Predict label for the given features.

read()

save(path)

Save this ML instance to the given path, a shortcut of 'write().save(path)'.

set(param, value)

Sets a parameter in the embedded param map.

setFeaturesCol(value)

Sets the value of featuresCol or featuresCols.

setFeaturesCols(value)

Sets the value of featuresCols.

setPredictionCol(value)

Sets the value of predictionCol.

transform(dataset[, params])

Transforms the input dataset with optional parameters.

write()

Attributes

cuml_params

Returns the dictionary of parameters intended for the underlying cuML class.

featuresCol

featuresCols

hasSummary

Indicates whether a training summary exists for this model instance.

initMode

k

maxIter

numFeatures

Returns the number of features the model was trained on.

num_workers

Number of cuML workers, where each cuML worker corresponds to one Spark task running on one GPU.

params

Returns all params ordered by name.

predictionCol

seed

tol

Methods Documentation

clear(param: Param) None#

Reset a Spark ML Param to its default value, setting matching cuML parameter, if exists.

clusterCenters() List[ndarray]#

Returns the list of cluster centers.

copy(extra: Optional[ParamMap] = None) P#
cpu() KMeansModel#

Return the PySpark ML KMeansModel

explainParam(param: Union[str, Param]) str#

Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.

explainParams() str#

Returns the documentation of all params with their optionally default values and user-supplied values.

extractParamMap(extra: Optional[ParamMap] = None) ParamMap#

Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.

Parameters:
extradict, optional

extra param values

Returns:
dict

merged param map

getFeaturesCol() Union[str, List[str]]#

Gets the value of featuresCol or featuresCols

getFeaturesCols() List[str]#

Gets the value of featuresCols or its default value.

getInitMode() str#

Gets the value of initMode

New in version 1.5.0.

getK() int#

Gets the value of k

New in version 1.5.0.

getMaxIter() int#

Gets the value of maxIter or its default value.

getOrDefault(param: Union[str, Param[T]]) Union[Any, T]#

Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.

getParam(paramName: str) Param#

Gets a param by its name.

getPredictionCol() str#

Gets the value of predictionCol or its default value.

getSeed() int#

Gets the value of seed or its default value.

getTol() float#

Gets the value of tol or its default value.

hasDefault(param: Union[str, Param[Any]]) bool#

Checks whether a param has a default value.

hasParam(paramName: str) bool#

Tests whether this instance contains a param with a given (string) name.

isDefined(param: Union[str, Param[Any]]) bool#

Checks whether a param is explicitly set by user or has a default value.

isSet(param: Union[str, Param[Any]]) bool#

Checks whether a param is explicitly set by user.

classmethod load(path: str) RL#

Reads an ML instance from the input path, a shortcut of read().load(path).

predict(value: Vector) int#

Predict label for the given features. cuML doesn’t support predicting 1 single sample. Fall back to PySpark ML KMeansModel

classmethod read() MLReader#
save(path: str) None#

Save this ML instance to the given path, a shortcut of ‘write().save(path)’.

set(param: Param, value: Any) None#

Sets a parameter in the embedded param map.

setFeaturesCol(value: Union[str, List[str]]) P#

Sets the value of featuresCol or featuresCols.

setFeaturesCols(value: List[str]) P#

Sets the value of featuresCols. Used when input vectors are stored as multiple feature columns.

setPredictionCol(value: str) P#

Sets the value of predictionCol.

transform(dataset: DataFrame, params: Optional[ParamMap] = None) DataFrame#

Transforms the input dataset with optional parameters.

New in version 1.3.0.

Parameters:
datasetpyspark.sql.DataFrame

input dataset

paramsdict, optional

an optional param map that overrides embedded params.

Returns:
pyspark.sql.DataFrame

transformed dataset

write() MLWriter#

Attributes Documentation

cuml_params#

Returns the dictionary of parameters intended for the underlying cuML class.

featuresCol: Param[str] = Param(parent='undefined', name='featuresCol', doc='features column name.')#
featuresCols = Param(parent='undefined', name='featuresCols', doc='features column names for multi-column input.')#
hasSummary#

Indicates whether a training summary exists for this model instance.

initMode: Param[str] = Param(parent='undefined', name='initMode', doc='The initialization algorithm. This can be either "random" to choose random points as initial cluster centers, or "k-means||" to use a parallel variant of k-means++')#
k: Param[int] = Param(parent='undefined', name='k', doc='The number of clusters to create. Must be > 1.')#
maxIter: Param[int] = Param(parent='undefined', name='maxIter', doc='max number of iterations (>= 0).')#
numFeatures#

Returns the number of features the model was trained on. If unknown, returns -1

num_workers#

Number of cuML workers, where each cuML worker corresponds to one Spark task running on one GPU.

params#

Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.

predictionCol: Param[str] = Param(parent='undefined', name='predictionCol', doc='prediction column name.')#
seed: Param[int] = Param(parent='undefined', name='seed', doc='random seed.')#
tol: Param[float] = Param(parent='undefined', name='tol', doc='the convergence tolerance for iterative algorithms (>= 0).')#