openfl.pipelines.kc_pipeline.KmeansTransformer#

class openfl.pipelines.kc_pipeline.KmeansTransformer(n_cluster=6)[source]#

Bases: Transformer

K-means transformer class for quantizing input data.

This class is a transformer that uses the K-means method for quantization.

n_cluster#

The number of clusters for the K-means.

Type:

int

lossy#

Indicates if the transformer is lossy.

Type:

bool

__init__(n_cluster=6)[source]#

Initialize KmeansTransformer.

Parameters:

n_cluster (int, optional) – The number of clusters for the K-means. Defaults to 6.

Methods

__init__([n_cluster])

Initialize KmeansTransformer.

backward(data, metadata, **kwargs)

Recover data array back to the original numerical type and the shape.

forward(data, **kwargs)

Quantize data into n_cluster levels of values.

backward(data, metadata, **kwargs)[source]#

Recover data array back to the original numerical type and the shape.

Parameters:
  • data – The flattened numpy array.

  • metadata – The dictionary containing information for recovering to original data array.

Returns:

The numpy array with original numerical type and shape.

Return type:

data

forward(data, **kwargs)[source]#

Quantize data into n_cluster levels of values.

Parameters:
  • data – The data to be quantized.

  • **kwargs – Variable arguments to pass.

Returns:

The quantized data. metadata: The metadata for the quantization.

Return type:

int_array