skcriteria.cmp.ranks_cmp
module¶
Ranking comparison routines.
- class skcriteria.cmp.ranks_cmp.RanksComparator(ranks)[source]¶
Bases:
SKCMethodABC
Rankings comparator object.
This class is intended to contain a collection of rankings on which you want to do comparative analysis.
All rankings must have exactly the same alternatives, although their order may vary.
All methods support the
untied
parameter, which serves to untie rankings in case there are results that can assign more than one alternative to the same position (e.g.``ELECTRE2``).- Parameters
ranks (list) – List of (name, ranking) tuples of
skcriteria.madm.RankResult
with the same alternatives.
See also
skcriteria.cmp.mkrank_cmp
Convenience function for simplified ranks comparator construction.
- property ranks¶
List of ranks in the comparator.
- property named_ranks¶
Dictionary-like object, with the following attributes.
Read-only attribute to access any rank parameter by user given name. Keys are ranks names and values are rannks parameters.
- to_dataframe(*, untied=False)[source]¶
Convert the entire RanksComparator into a dataframe.
The alternatives are the rows, and the different rankings are the columns.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.- Returns
A RanksComparator as pandas DataFrame.
- Return type
pd.DataFrame
- corr(*, untied=False, **kwargs)[source]¶
Compute pairwise correlation of rankings, excluding NA/null values.
By default the pearson correlation coefficient is used.
Please check the full documentation of a
pandas.DataFrame.corr()
method for details about the implementation.- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.kwargs – Other keyword arguments are passed to the
pandas.DataFrame.corr()
method.
- Returns
A DataFrame with the correlation between rankings.
- Return type
pd.DataFrame
- cov(*, untied=False, **kwargs)[source]¶
Compute pairwise covariance of rankings, excluding NA/null values.
Please check the full documentation of a
pandas.DataFrame.cov()
method for details about the implementation.- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.kwargs – Other keyword arguments are passed to the
pandas.DataFrame.cov()
method.
- Returns
A DataFrame with the covariance between rankings.
- Return type
pd.DataFrame
- r2_score(*, untied=False, **kwargs)[source]¶
Compute pairwise coefficient of determination regression score function of rankings, excluding NA/null values.
Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).
Please check the full documentation of a
sklearn.metrics.r2_score
function for details about the implementation and the behaviour.- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.kwargs – Other keyword arguments are passed to the
sklearn.metrics.r2_score()
function.
- Returns
A DataFrame with the coefficient of determination between rankings.
- Return type
pd.DataFrame
- distance(*, untied=False, metric='hamming', **kwargs)[source]¶
Compute pairwise distance between rankings.
By default the ‘hamming’ distance is used, which is simply the proportion of disagreeing components in Two rankings.
Please check the full documentation of a
scipy.spatial.distance.pdist
function for details about the implementation and the behaviour.- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.metric (str or function, default
"hamming"
) – The distance metric to use. The distance function can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘jensenshannon’, ‘kulczynski1’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’.kwargs – Other keyword arguments are passed to the
scipy.spatial.distance.pdist()
function.
- Returns
A DataFrame with the distance between rankings.
- Return type
pd.DataFrame
- property plot¶
Plot accessor.
- class skcriteria.cmp.ranks_cmp.RanksComparatorPlotter(ranks_cmp)[source]¶
Bases:
AccessorABC
RanksComparator plot utilities.
Kind of plot to produce:
‘flow’ : Changes in the rankings of the alternatives as flow lines (default)
‘reg’ : Pairwise rankings data and a linear regression model fit plot.
‘heatmap’ : Rankings as a color-encoded matrix.
‘corr’ : Pairwise correlation of rankings as a color-encoded matrix.
‘cov’ : Pairwise covariance of rankings as a color-encoded matrix.
‘r2_score’ : Pairwise coefficient of determination regression score function of rankings as a color-encoded matrix.
‘distance’ : Pairwise distance between rankings as a color-encoded matrix.
‘box’ : Box-plot of rankings with respect to alternatives
‘bar’ : Ranking of alternatives by method with vertical bars.
‘barh’ : Ranking of alternatives by method with horizontal bars.
- flow(*, untied=False, grid_kws=None, **kwargs)[source]¶
Represents changes in the rankings of the alternatives as lines flowing through the ranking-methods.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.grid_kws (dict or None) – Dict with keyword arguments passed to
matplotlib.axes.plt.Axes.grid
kwargs – Other keyword arguments are passed to the
seaborn.lineplot()
function. except for data, estimator and sort.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- reg(*, untied=False, r2=True, palette=None, legend=True, r2_fmt='.2g', r2_kws=None, **kwargs)[source]¶
Plot a pairwise rankings data and a linear regression model fit.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.r2 (bool, default
True
) – If True, the coefficient of determination results are added to the regression legend.palette (matplotlib/seaborn color palette, default
None
) – Set of colors for mapping the hue variable.legend (bool, default
True
) – If False, suppress the legend for semantic variables.r2_fmt (str, default
"2.g"
) – String formatting code to use when adding the coefficient of determination.r2_kws (dict or None) – Dict with keywords arguments passed to
sklearn.metrics.r2_score()
function.kwargs – Other keyword arguments are passed to the
seaborn.lineplot()
function.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- heatmap(*, untied=False, **kwargs)[source]¶
Plot the rankings as a color-encoded matrix.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.kwargs – Other keyword arguments are passed to the
seaborn.heatmap()
function.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- corr(*, untied=False, corr_kws=None, **kwargs)[source]¶
Plot the pairwise correlation of rankings as a color-encoded matrix.
By default the pearson correlation coefficient is used.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.corr_kws (dict or None) – Dict with keywords arguments passed the
pandas.DataFrame.corr()
method.kwargs – Other keyword arguments are passed to the
seaborn.heatmap()
function.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- cov(*, untied=False, cov_kws=None, **kwargs)[source]¶
Plot the pairwise covariance of rankings as a color-encoded matrix.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.cov_kws (dict or None) – Dict with keywords arguments passed the
pandas.DataFrame.cov()
method.kwargs – Other keyword arguments are passed to the
seaborn.heatmap()
function.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- r2_score(untied=False, r2_kws=None, **kwargs)[source]¶
Plot the pairwise coefficient of determination regression score function of rankings as a color-encoded matrix.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.cov_kws (dict or None) – Dict with keywords arguments passed the
pandas.DataFrame.cov()
method.kwargs – Other keyword arguments are passed to the
seaborn.heatmap()
function.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- distance(*, untied=False, metric='hamming', distance_kws=None, **kwargs)[source]¶
Plot the pairwise distance between rankings as a color-encoded matrix.
By default the ‘hamming’ distance is used, which is simply the proportion of disagreeing components in Two rankings.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.metric (str or function, default
"hamming"
) – The distance metric to use. The distance function can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘jensenshannon’, ‘kulczynski1’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’.distance_kws (dict or None) – Dict with keywords arguments passed the
scipy.spatial.distance.pdist
functionkwargs – Other keyword arguments are passed to the
seaborn.heatmap()
function.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- box(*, untied=False, **kwargs)[source]¶
Draw a boxplot to show rankings with respect to alternatives.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.kwargs – Other keyword arguments are passed to the
seaborn.boxplot()
function.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- bar(*, untied=False, **kwargs)[source]¶
Draw plot that presents ranking of alternatives by method with vertical bars.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.kwargs – Other keyword arguments are passed to the
pandas.Dataframe.plot.bar()
method.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- barh(*, untied=False, **kwargs)[source]¶
Draw plot that presents ranking of alternatives by method with horizontal bars.
- Parameters
untied (bool, default
False
) – If it isTrue
and any ranking has ties, theRankResult.untied_rank_
property is used to assign each alternative a single ranked order. On the other hand, if it isFalse
the rankings are used as they are.kwargs – Other keyword arguments are passed to the
pandas.Dataframe.plot.barh()
method.
- Return type
matplotlib.axes.Axes or numpy.ndarray of them
- skcriteria.cmp.ranks_cmp.mkrank_cmp(*ranks)[source]¶
Construct a RankComparator from the given rankings.
This is a shorthand for the RankComparator constructor; it does not require, and does not permit, naming the estimators. Instead, their names will be set to the method attribute of the rankings automatically.
- Parameters
*ranks (list of RankResult objects) – List of the scikit-criteria RankResult objcects.
- Returns
rcmp – Returns a scikit-criteria
RanksComparator
object.- Return type