skcriteria.preprocessing.scalers module

Functionalities for scale values based on differrent strategies.

In addition to the Transformers, a collection of an MCDA agnostic functions are offered to scale an array along an arbitrary axis.

class skcriteria.preprocessing.scalers.MaxScaler(target)[source]

Bases: skcriteria.core.methods.SKCMatrixAndWeightTransformerABC

Scaler based on the maximum values.

\[\overline{X}_{ij} = \frac{X_{ij}}{\max_{X_{ij}}}\]

If the scaler is configured to work with ‘matrix’ each value of each criteria is divided by the maximum value of that criteria. In other hand if is configure to work with ‘weights’, each value of weight is divided by the maximum value the weights.

class skcriteria.preprocessing.scalers.MinMaxScaler(target)[source]

Bases: skcriteria.core.methods.SKCMatrixAndWeightTransformerABC

Scaler based on the range.

\[\overline{X}_{ij} = \frac{X_{ij} - \min{X_{ij}}}{\max_{X_{ij}} - \min_{X_{ij}}}\]

If the scaler is configured to work with ‘matrix’ each value of each criteria is divided by the range of that criteria. In other hand if is configure to work with ‘weights’, each value of weight is divided by the range the weights.

class skcriteria.preprocessing.scalers.StandarScaler(target)[source]

Bases: skcriteria.core.methods.SKCMatrixAndWeightTransformerABC

Standardize the dm by removing the mean and scaling to unit variance.

The standard score of a sample x is calculated as:

z = (x - u) / s

where u is the mean of the values, and s is the standard deviation of the training samples or one if with_std=False.

class skcriteria.preprocessing.scalers.SumScaler(target)[source]

Bases: skcriteria.core.methods.SKCMatrixAndWeightTransformerABC

Scalerbased on the total sum of values.

\[\overline{X}_{ij} = \frac{X_{ij}}{\sum\limits_{j=1}^m X_{ij}}\]

If the scaler is configured to work with ‘matrix’ each value of each criteria is divided by the total sum of all the values of that criteria. In other hand if is configure to work with ‘weights’, each value of weight is divided by the total sum of all the weights.

class skcriteria.preprocessing.scalers.VectorScaler(target)[source]

Bases: skcriteria.core.methods.SKCMatrixAndWeightTransformerABC

Scaler based on the norm of the vector..

\[\overline{X}_{ij} = \frac{X_{ij}}{\sqrt{\sum\limits_{j=1}^m X_{ij}^{2}}}\]

If the scaler is configured to work with ‘matrix’ each value of each criteria is divided by the norm of the vector defined by the values of that criteria. In other hand if is configure to work with ‘weights’, each value of weight is divided by the vector defined by the values of the weights.

skcriteria.preprocessing.scalers.scale_by_max(arr, axis=None)[source]

Divide of every value on the array by max value along an axis.

\[\overline{X}_{ij} = \frac{X_{ij}}{\max_{X_{ij}}}\]
Parameters
  • arr (numpy.ndarray like.) – A array with values

  • axis (int optional) – Axis along which to operate. By default, flattened input is used.

Returns

array of ratios

Return type

numpy.ndarray

Examples

>>> from skcriteria.preprocess import scale_by_max
>>> mtx = [[1, 2], [3, 4]]

# ratios with the max value of the array
>>> scale_by_max(mtx)
array([[ 0.25,  0.5 ],
       [ 0.75,  1.  ]])

# ratios with the max value of the arr by column
>>> scale_by_max(mtx, axis=0)
array([[ 0.33333334,  0.5],
       [ 1.        ,  1. ]])

# ratios with the max value of the array by row
>>> scale_by_max(mtx, axis=1)
array([[ 0.5 ,  1.],
       [ 0.75,  1.]])
skcriteria.preprocessing.scalers.scale_by_minmax(arr, axis=None)[source]

Fraction of the range normalizer.

Subtracts to each value of the array the minimum and then divides it by the total range.

\[\overline{X}_{ij} = \frac{X_{ij} - \min{X_{ij}}}{\max_{X_{ij}} - \min_{X_{ij}}}\]
Parameters
  • arr (numpy.ndarray like.) – A array with values

  • axis (int optional) – Axis along which to operate. By default, flattened input is used.

Returns

array of ratios

Return type

numpy.ndarray

Examples

>>> from skcriteria.preprocess import scale_by_minmax
>>> mtx = [[1, 2], [3, 4]]

# ratios with the range of the array
>>> scale_by_minmax(mtx)
array([[0.        , 0.33333333],
       [0.66666667, 1.        ]])

# ratios with the range by column
>>> scale_by_minmax(mtx, axis=0)
array([[0., 0.],
       [1., 1.]])

# ratios with the range by row
>>> scale_by_minmax(mtx, axis=1)
array([[0., 1.],
      [0., 1.]])
skcriteria.preprocessing.scalers.scale_by_stdscore(arr, axis=None)[source]

Standardize the values by removing the mean and divided by the std-dev.

The standard score of a sample x is calculated as:

\[z = (x - \mu) / \sigma\]
Parameters
  • arr (numpy.ndarray like.) – A array with values

  • axis (int optional) – Axis along which to operate. By default, flattened input is used.

Returns

array of ratios

Return type

numpy.ndarray

Examples

>>> from skcriteria.preprocess import scale_by_stdscore
>>> mtx = [[1, 2], [3, 4]]

# ratios with the max value of the array
>>> scale_by_stdscore(mtx)
array([[-1.34164079, -0.4472136 ],
       [ 0.4472136 ,  1.34164079]])

# ratios with the max value of the arr by column
>>> scale_by_stdscore(mtx, axis=0)
array([[-1., -1.],
       [ 1.,  1.]])

# ratios with the max value of the array by row
>>> scale_by_stdscore(mtx, axis=1)
array([[-1.,  1.],
       [-1.,  1.]])
skcriteria.preprocessing.scalers.scale_by_sum(arr, axis=None)[source]

Divide of every value on the array by sum of values along an axis.

\[\overline{X}_{ij} = \frac{X_{ij}}{\sum\limits_{j=1}^m X_{ij}}\]
Parameters
  • arr (numpy.ndarray like.) – A array with values

  • axis (int optional) – Axis along which to operate. By default, flattened input is used.

Returns

array of ratios

Return type

numpy.ndarray

Examples

>>> from skcriteria.preprocess import scale_by_sum
>>> mtx = [[1, 2], [3, 4]]

>>> scale_by_sum(mtx) # ratios with the sum of the array
array([[ 0.1       ,  0.2       ],
       [ 0.30000001,  0.40000001]])

# ratios with the sum of the array by column
>>> scale_by_sum(mtx, axis=0)
array([[ 0.25      ,  0.33333334],
       [ 0.75      ,  0.66666669]])

# ratios with the sum of the array by row
>>> scale_by_sum(mtx, axis=1)
array([[ 0.33333334,  0.66666669],
       [ 0.42857143,  0.5714286 ]])
skcriteria.preprocessing.scalers.scale_by_vector(arr, axis=None)[source]

Divide the array by norm of values defined vector along an axis.

Calculates the set of ratios as the square roots of the sum of squared responses of a given axis as denominators. If axis is None sum all the array.

\[\overline{X}_{ij} = \frac{X_{ij}}{\sqrt{\sum\limits_{j=1}^m X_{ij}^{2}}}\]
Parameters
  • arr (numpy.ndarray like.) – A array with values

  • axis (int optional) – Axis along which to operate. By default, flattened input is used.

Returns

array of ratios

Return type

numpy.ndarray

Examples

>>> from skcriteria.preprocess import scale_by_vector
>>> mtx = [[1, 2], [3, 4]]

# ratios with the vector value of the array
>>> scale_by_vector(mtx)
array([[ 0.18257418,  0.36514837],
       [ 0.54772252,  0.73029673]])

# ratios by column
>>> scale_by_vector(mtx, axis=0)
array([[ 0.31622776,  0.44721359],
       [ 0.94868326,  0.89442718]])

# ratios by row
>>> scale_by_vector(mtx, axis=1)
array([[ 0.44721359,  0.89442718],
       [ 0.60000002,  0.80000001]])