milia.features.scale#

Named scalers, so a pipeline axis can be swept by name.

Functions

rangescale(values[, axis])

Scale each slice to its own range, so that only its shape remains.

scale(X, name)

Fit the named scaler on the data and return the scaled array.

scaler(name)

A fresh, unfitted scaler by name.

standardise(values[, axis])

Centre each slice and scale it to unit standard deviation.

milia.features.scale.scaler(name)#

A fresh, unfitted scaler by name.

Parameters:

name (str) – One of SCALERS: "none", "standard", "minmax", "robust", "quantile" or "power".

Return type:

object

Returns:

The scikit-learn transformer.

Raises:

ValueError – If the name is unknown.

Examples

>>> type(scaler("robust")).__name__
'RobustScaler'
milia.features.scale.scale(X, name)#

Fit the named scaler on the data and return the scaled array.

Parameters:
Return type:

ndarray

Returns:

The scaled data.

Examples

>>> scale([[0.0], [5.0], [10.0]], "minmax").ravel().tolist()
[0.0, 0.5, 1.0]
milia.features.scale.rangescale(values, axis=-1)#

Scale each slice to its own range, so that only its shape remains.

The values of every slice along axis are mapped linearly onto zero to one. This removes the level and the amplitude of a profile and keeps its timing, as the peak normalisation of a household profile does. A slice without range is mapped to zero.

Parameters:
  • values (ArrayLike) – Array of any shape.

  • axis (int) – Axis along which each slice is scaled; the last by default.

Return type:

ndarray

Returns:

An array of the same shape, each slice with minimum zero and maximum one.

Examples

>>> rangescale([[1.0, 2.0, 3.0], [10.0, 10.0, 10.0]]).tolist()
[[0.0, 0.5, 1.0], [0.0, 0.0, 0.0]]
milia.features.scale.standardise(values, axis=-1)#

Centre each slice and scale it to unit standard deviation.

The mean of the product of two standardised slices is their Pearson correlation, so the inner products of the result are correlations. A slice without variation is mapped to zero.

Parameters:
  • values (ArrayLike) – Array of any shape.

  • axis (int) – Axis along which each slice is standardised; the last by default.

Return type:

ndarray

Returns:

An array of the same shape, each slice with mean zero and standard deviation one (zero when constant).

Examples

>>> standardise([[1.0, 2.0, 3.0], [5.0, 5.0, 5.0]]).round(3).tolist()
[[-1.225, 0.0, 1.225], [0.0, 0.0, 0.0]]