skcriteria.preprocessing.scalers module

Functionalities for scale values based on different 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.StandarScaler(target, *, with_mean=True, with_std=True)[source]

Bases: 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.

This is a thin wrapper around sklearn.preprocessing.StandarScaler.

Parameters:
  • with_mean (bool, default=True) – If True, center the data before scaling.

  • with_std (bool, default=True) – If True, scale the data to unit variance (or equivalently, unit standard deviation).

property with_mean

True if the features will be center before scaling.

property with_std

True if the features will be scaled to the unit variance.

class skcriteria.preprocessing.scalers.MinMaxScaler(target, *, clip=False, criteria_range=(0, 1))[source]

Bases: SKCMatrixAndWeightTransformerABC

Scaler based on the range.

The matrix transformation is given by:

X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min

And the weight transformation:

X_std = (X - X.min(axis=None)) / (X.max(axis=None) - X.min(axis=None))
X_scaled = X_std * (max - min) + min

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.

This is a thin wrapper around sklearn.preprocessing.MinMaxScaler.

Parameters:
  • criteria_range (tuple (min, max), default=(0, 1)) – Desired range of transformed data.

  • clip (bool, default=False) – Set to True to clip transformed values of held-out data to provided criteria_range.

property clip

True if the transformed values will be clipped to held-out the value provided criteria_range.

property criteria_range

Range of transformed data.

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

Bases: SKCMatrixAndWeightTransformerABC

Scaler based on the maximum values.

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.

This estimator scales and translates each criteria individually such that the maximal absolute value of each criteria in the training set will be 1.0. It does not shift/center the data, and thus does not destroy any sparsity.

This is a thin wrapper around sklearn.preprocessing.MaxAbsScaler.

class skcriteria.preprocessing.scalers.MaxScaler(*args, **kwargs)[source]

Bases: MaxAbsScaler

Scaler based on the maximum values.

From skcriteria >= 0.8 this is a thin wrapper around sklearn.preprocessing.MaxAbsScaler.

Deprecated since version 0.8: Use skcriteria.preprocessing.scalers.MaxAbsScaler instead

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]])
class skcriteria.preprocessing.scalers.VectorScaler(target)[source]

Bases: 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_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 ]])
class skcriteria.preprocessing.scalers.SumScaler(target)[source]

Bases: 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.

skcriteria.preprocessing.scalers.matrix_scale_by_cenit_distance(matrix, objectives)[source]

Calculate a scores with respect to an ideal and anti-ideal alternative.

For every criterion \(f\) of this multicriteria problem we define a membership function \(x_j\) mapping the values of \(f_j\) to the interval [0, 1].

The result score \(x_{aj}`expresses the degree to which the alternative :math:`a\) is close to the ideal value \(f_{j}^*\), which is the best performance in criterion , and far from the anti-ideal value \(f_{j^*}\), which is the worst performance in criterion \(j\). Both ideal and anti-ideal, are achieved by at least one of the alternatives under consideration.

\[x_{aj} = \frac{f_j(a) - f_{j^*}}{f_{j}^* - f_{j^*}}\]
class skcriteria.preprocessing.scalers.CenitDistanceMatrixScaler[source]

Bases: SKCTransformerABC

Relative scores with respect to an ideal and anti-ideal alternative.

For every criterion \(f\) of this multicriteria problem we define a membership function \(x_j\) mapping the values of \(f_j\) to the interval [0, 1].

The result score \(x_{aj}`expresses the degree to which the alternative :math:`a\) is close to the ideal value \(f_{j}^*\), which is the best performance in criterion , and far from the anti-ideal value \(f_{j^*}\), which is the worst performance in criterion \(j\). Both ideal and anti-ideal, are achieved by at least one of the alternatives under consideration.

\[x_{aj} = \frac{f_j(a) - f_{j^*}}{f_{j}^* - f_{j^*}}\]

References

[Diakoulaki et al., 1995]