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.Critic(correlation='pearson', scale=True)[source]¶
Bases:
skcriteria.core.methods.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" or "spearman"] or callable. (default "pearson")) – 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 thekendall
correlation is also available implemented. It is also possible to provide a function that receives as a single parameter, the matrix of alternatives, and returns the correlation matrix.scale (bool (default
True
)) – True if it is necessary to scale the data withskcriteria.preprocesisng.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
- CORRELATION = {'pearson': <function pearson_correlation>, 'spearman': <function spearman_correlation>}¶
- property correlation¶
Correlation function.
- property scale¶
Return if it is necessary to scale the data.
- class skcriteria.preprocessing.weighters.EntropyWeighter[source]¶
Bases:
skcriteria.core.methods.SKCWeighterABC
Assigns 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.This transformer will normalize the criteria if they don’t sum to 1.
See also
scipy.stats.entropy
Calculate the entropy of a distribution for given probability values.
- class skcriteria.preprocessing.weighters.EqualWeighter(base_value=1)[source]¶
Bases:
skcriteria.core.methods.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.
- class skcriteria.preprocessing.weighters.StdWeighter[source]¶
Bases:
skcriteria.core.methods.SKCWeighterABC
Set as weight the normalized standard deviation of each criterion.
- skcriteria.preprocessing.weighters.critic_weights(matrix, objectives, correlation=<function pearson_correlation>, scale=True)[source]¶
Execute the CRITIC method without any validation.
- skcriteria.preprocessing.weighters.entropy_weights(matrix)[source]¶
Calculate the weights as 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.This routine will normalize the criteria if they don’t sum to 1.
See also
scipy.stats.entropy
Calculate the entropy of a distribution for given probability values.
Examples
>>> from skcriteria.preprocess import entropy_weights >>> mtx = [[1, 2], [3, 4]]
>>> entropy_weights(mtx) array([0.46906241, 0.53093759])
- 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])
- skcriteria.preprocessing.weighters.pearson_correlation(arr)[source]¶
Return Pearson product-moment correlation coefficients.
This function is a thin wrapper of
numpy.corrcoef
.- 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
.- 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.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{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.- 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])