openfl.pipelines.kc_pipeline.KmeansTransformer

class openfl.pipelines.kc_pipeline.KmeansTransformer(n_cluster=6)

Bases: Transformer

K-means transformer class for quantizing input data.

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

Class Attributes:
  • n_cluster (int) – The number of clusters for the K-means.

  • lossy (bool) – Indicates if the transformer is lossy.

Methods

backward

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

forward

Quantize data into n_cluster levels of values.

backward(data, metadata, **kwargs)

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:

data – The numpy array with original numerical type and shape.

forward(data, **kwargs)

Quantize data into n_cluster levels of values.

Parameters:
  • data – The data to be quantized.

  • **kwargs – Variable arguments to pass.

Returns:
  • int_array – The quantized data.

  • metadata – The metadata for the quantization.