skcriteria.preprocessing.weighters module

Functionalities for weight the criteria.

In addition to the main functionality, an MCDA agnostic function is offered to calculate weights to a matrix along an arbitrary axis.

class skcriteria.preprocessing.weighters.SKCWeighterABC[source]

Bases: SKCTransformerABC

Abstract class capable of determine the weights of the matrix.

This abstract class require to redefine _weight_matrix, instead of _transform_data.

skcriteria.preprocessing.weighters.equal_weights(matrix, base_value=1)[source]

Use the same weights for all criteria.

The result values are normalized by the number of columns.

\[w_j = \frac{base\_value}{m}\]

Where $m$ is the number os columns/criteria in matrix.

Parameters:
  • matrix (numpy.ndarray like.) – The matrix of alternatives on which to calculate weights.

  • base_value (int or float.) – Value to be normalized by the number of criteria to create the weights.

Returns:

array of weights

Return type:

numpy.ndarray

Examples

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

>>> equal_weights(mtx)
array([0.5, 0.5])
class skcriteria.preprocessing.weighters.EqualWeighter(base_value=1.0)[source]

Bases: SKCWeighterABC

Assigns the same weights to all criteria.

The algorithm calculates the weights as the ratio of base_value by the total criteria.

property base_value

Value to be normalized by the number of criteria.

skcriteria.preprocessing.weighters.std_weights(matrix)[source]

Calculate weights as the standard deviation of each criterion.

The result is normalized by the number of columns.

\[w_j = \frac{s_j}{m}\]

Where $m$ is the number os columns/criteria in matrix.

Parameters:

matrix (numpy.ndarray like.) – The matrix of alternatives on which to calculate weights.

Returns:

array of weights

Return type:

numpy.ndarray

Examples

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

>>> std_weights(mtx)
 array([0.5, 0.5])
class skcriteria.preprocessing.weighters.StdWeighter[source]

Bases: SKCWeighterABC

Set as weight the normalized standard deviation of each criterion.

skcriteria.preprocessing.weighters.entropy_weights(matrix)[source]

Calculate the weights as the complement of the entropy of each criterion.

It uses the underlying scipy.stats.entropy function which assumes that the values of the criteria are probabilities of a distribution.

The logarithmic base to use is the number of rows/alternatives in the matrix.

This routine will normalize the sum of the weights to 1.

See also

scipy.stats.entropy

Calculate the entropy of a distribution for given probability values.

class skcriteria.preprocessing.weighters.EntropyWeighter[source]

Bases: SKCWeighterABC

Assigns the complement of the entropy of the criteria as weights.

It uses the underlying scipy.stats.entropy function which assumes that the values of the criteria are probabilities of a distribution.

The logarithmic base to use is the number of rows/alternatives in the matrix.

This transformer will normalize the sum of the weights to 1.

See also

scipy.stats.entropy

Calculate the entropy of a distribution for given probability values.

skcriteria.preprocessing.weighters.pearson_correlation(arr)[source]

Return Pearson product-moment correlation coefficients.

This function is a thin wrapper of numpy.corrcoef.

Deprecated since version 0.8: Please use pd.DataFrame(arr.T).correlation('pearson')

Parameters:

arr (array like) – A 1-D or 2-D array containing multiple variables and observations. Each row of arr represents a variable, and each column a single observation of all those variables.

Returns:

R – The correlation coefficient matrix of the variables.

Return type:

numpy.ndarray

See also

numpy.corrcoef

Return Pearson product-moment correlation coefficients.

skcriteria.preprocessing.weighters.spearman_correlation(arr)[source]

Calculate a Spearman correlation coefficient.

This function is a thin wrapper of scipy.stats.spearmanr.

Deprecated since version 0.8: Please use pd.DataFrame(arr.T).correlation('spearman')

Parameters:

arr (array like) – A 1-D or 2-D array containing multiple variables and observations. Each row of arr represents a variable, and each column a single observation of all those variables.

Returns:

R – The correlation coefficient matrix of the variables.

Return type:

numpy.ndarray

See also

scipy.stats.spearmanr

Calculate a Spearman correlation coefficient with associated p-value.

skcriteria.preprocessing.weighters.critic_weights(matrix, objectives, correlation='pearson', scale=True)[source]

Execute the CRITIC method without any validation.

class skcriteria.preprocessing.weighters.CRITIC(correlation='pearson', scale=True)[source]

Bases: SKCWeighterABC

CRITIC (CRiteria Importance Through Intercriteria Correlation).

The method aims at the determination of objective weights of relative importance in MCDM problems. The weights derived incorporate both contrast intensity and conflict which are contained in the structure of the decision problem.

Parameters:
  • correlation (str ["pearson", "spearman", "kendall"] or callable.) – This is the correlation function used to evaluate the discordance between two criteria. In other words, what conflict does one criterion a criterion with respect to the decision made by the other criteria. By default the pearson correlation is used, and the spearman and kendall correlation is also available implemented. It is also possible to provide a callable with input two 1d arrays and returning a float. Note that the returned matrix from corr will have 1 along the diagonals and will be symmetric regardless of the callable’s behavior

  • scale (bool (default True)) – True if it is necessary to scale the data with skcriteria.preprocessing.matrix_scale_by_cenit_distance prior to calculating the correlation

Warning

UserWarning:

If some objective is to minimize. The original paper only suggests using it against maximization criteria, but there is no real mathematical constraint to use it for minimization.

References

[Diakoulaki et al., 1995]

CORRELATION = ('pearson', 'spearman', 'kendall')
property scale

Return if it is necessary to scale the data.

property correlation

Correlation function.

class skcriteria.preprocessing.weighters.Critic(*args, **kwargs)[source]

Bases: CRITIC

CRITIC (CRiteria Importance Through Intercriteria Correlation).

The method aims at the determination of objective weights of relative importance in MCDM problems. The weights derived incorporate both contrast intensity and conflict which are contained in the structure of the decision problem.

Deprecated since version 0.8: Use skcriteria.preprocessing.weighters.CRITIC instead

Parameters:
  • correlation (str ["pearson", "spearman", "kendall"] or callable.) – This is the correlation function used to evaluate the discordance between two criteria. In other words, what conflict does one criterion a criterion with respect to the decision made by the other criteria. By default the pearson correlation is used, and the spearman and kendall correlation is also available implemented. It is also possible to provide a callable with input two 1d arrays and returning a float. Note that the returned matrix from corr will have 1 along the diagonals and will be symmetric regardless of the callable’s behavior

  • scale (bool (default True)) – True if it is necessary to scale the data with skcriteria.preprocessing.matrix_scale_by_cenit_distance prior to calculating the correlation

Warning

UserWarning:

If some objective is to minimize. The original paper only suggests using it against maximization criteria, but there is no real mathematical constraint to use it for minimization.

References

[Diakoulaki et al., 1995]

skcriteria.preprocessing.weighters.merec_weights(matrix, objectives)[source]

Execute the MEREC method without any validation.

class skcriteria.preprocessing.weighters.MEREC[source]

Bases: SKCWeighterABC

MEREC: Method based on the Removal Effects of Criteria.

The MEREC method computes objective weights for each criterion based on its impact on the overall performance of alternatives when removed. The idea is that the more a criterion affects the total evaluation when excluded, the more important it is.

This implementation includes a simple linear normalization.

Reference

[Keshavarz-Ghorabaee et al., 2021]

skcriteria.preprocessing.weighters.gini_weights(matrix)[source]

Calculates weights using the Gini coefficient.

Computes the weights for each criterion (column) of the input matrix by calculating the Gini coefficient of each column, then normalizing those values to sum to 1.

The columns are sorted to use the more efficient formula for the Gini coefficient:

\[G = \frac{1}{n} \left( n + 1 - 2 \cdot \frac{ \sum_{i=1}^n \left( \sum_{j=1}^i x_j \right) }{ \sum_{i=1}^n x_i } \right)\]
class skcriteria.preprocessing.weighters.GiniWeighter[source]

Bases: SKCWeighterABC

Calculates the weights with the Gini coefficient.

The method aims at the determination of objective weights of relative importance in MCDM problems. It uses the Gini coefficient of the data of each criterion to assign the weights, giving a higher weight to a more unequal distribution. It takes the decision matrix as a parameter.

References

[Li & Chi, 2009]

skcriteria.preprocessing.weighters.rancom_weights(weights)[source]

RANCOM (RANking COMparison) weighting method.

The RANCOM method is designed to handle expert inaccuracies in multi-criteria decision making by transforming initial weight values through ranking comparison. The method builds a Matrix of Ranking Comparison (MAC) where all weights are compared pairwise, then calculates Summed Criteria Weights (SWC) to derive final normalized weights.

The method operates under the following assumptions:

  • The sum of input weights equals 1

  • Lower weight values correspond to higher importance

  • Ties between criteria are allowed

Algorithm Steps:

  1. Convert weights to rankings (lower weight = higher rank/importance)

  2. Build MAC (Matrix of Ranking Comparison): An nxn matrix where rankings are compared pairwise with values:

    • aij = 1 if rank_i < rank_j (criteria i is more important than j)

    • aij = 0.5 if rank_i = rank_j (criteria i and j have equal importance)

    • aij = 0 if rank_i > rank_j (criteria i is less important than j)

  3. Calculate SWC (Summed Criteria Weights): Sum each row of the MAC matrix

  4. Normalize final weights: wi = SWCi / sum(SWC)

Parameters:

weights (array-like) – Input weights. Lower values correspond to higher importance.

Notes

  • RANCOM is particularly useful when dealing with subjective weight assignments from experts where small inaccuracies in weight specification can significantly impact results.

  • The method provides a systematic way to handle ranking inconsistencies.

  • Unlike other weighting methods, RANCOM transforms existing weights rather than deriving weights from the decision matrix.

Examples

>>> from skcriteria.preprocessing import rancom_weights
>>> weights = [0.4, 0.2, 0.25, 0.05]
>>> rancom_weights(weights)
array([0.4375, 0.1875, 0.3125, 0.0625])
class skcriteria.preprocessing.weighters.RANCOM[source]

Bases: SKCWeighterABC

Ranking Comparison (RANCOM) method.

The RANCOM method is designed to handle expert inaccuracies in multi-criteria decision making by transforming initial weight values through ranking comparison.

The method builds a Matrix of Ranking Comparison (MAC) where all weights are compared pairwise, then calculates Summed Criteria Weights (SWC) to derive final normalized weights.

RANCOM uses predefined weights provided through the weighting process and does not require additional configuration parameters.

Warning

UserWarning

If there are fewer than five weights. The original paper suggests that RANCOM works better with five or more criteria, though nothing prevents its use with four or fewer criteria.

References

[Wieckowski et al., 2023]