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 thespearman
andkendall
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 behaviorscale (bool (default
True
)) – True if it is necessary to scale the data withskcriteria.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
- 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 thespearman
andkendall
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 behaviorscale (bool (default
True
)) – True if it is necessary to scale the data withskcriteria.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