[1]:
%config Completer.use_jedi = True
[2]:
from mcda import PerformanceTable, normalize
from mcda.scales import QuantitativeScale, QualitativeScale, PreferenceDirection
[3]:
alternatives = [
    "Breaking Bad", "The Sopranos", "The Wire",
    "Better Call Saul", "Game Of Thrones", "Sherlock",
    "Dexter", "Band Of Brothers", "Mad Men"
]

scales = {
    "Critical Acclaim": QuantitativeScale(0, 100),
    "Awards": QuantitativeScale(0),
    "Rewatchability": QualitativeScale({"*": 1, "**": 2, "***": 3, "****": 4, "*****": 5}),
    "Influence": QuantitativeScale(0, 10, preference_direction=PreferenceDirection.MIN),
    "Consistency": QuantitativeScale(0, 3, preference_direction=PreferenceDirection.MIN)
}

criteria = list(scales.keys())

performance_table = PerformanceTable(
    [
        [97, 16, "*****", 3, 0.35],
        [92, 21, "*****", 1, 0.30],
        [94, 2, "****", 2, 0.25],
        [87, 0, "****", 8, 0.40],
        [86, 59, "***", 5, 1.90],
        [84, 9, "****", 7, 1.30],
        [76, 4, "**", 9, 2.10],
        [89, 6, "***", 6, 0.20],
        [88, 16, "****", 4, 0.60]
    ],
    scales=scales,
    alternatives=alternatives,
    criteria=criteria,
)
performance_table.data
[3]:
Critical Acclaim Awards Rewatchability Influence Consistency
Breaking Bad 97 16 ***** 3 0.35
The Sopranos 92 21 ***** 1 0.30
The Wire 94 2 **** 2 0.25
Better Call Saul 87 0 **** 8 0.40
Game Of Thrones 86 59 *** 5 1.90
Sherlock 84 9 **** 7 1.30
Dexter 76 4 ** 9 2.10
Band Of Brothers 89 6 *** 6 0.20
Mad Men 88 16 **** 4 0.60
[4]:
performance_table.scales
[4]:
{'Critical Acclaim': QuantitativeScale(interval=[0, 100]),
 'Awards': QuantitativeScale(interval=[0, inf]),
 'Rewatchability': QualitativeScale(values={'*': 1, '**': 2, '***': 3, '****': 4, '*****': 5}),
 'Influence': QuantitativeScale(interval=[0, 10], preference_direction=PreferenceDirection.MIN),
 'Consistency': QuantitativeScale(interval=[0, 3], preference_direction=PreferenceDirection.MIN)}
[5]:
normalize(performance_table).data
[5]:
Critical Acclaim Awards Rewatchability Influence Consistency
Breaking Bad 0.97 0.0 1.00 0.7 0.883333
The Sopranos 0.92 0.0 1.00 0.9 0.900000
The Wire 0.94 0.0 0.75 0.8 0.916667
Better Call Saul 0.87 0.0 0.75 0.2 0.866667
Game Of Thrones 0.86 0.0 0.50 0.5 0.366667
Sherlock 0.84 0.0 0.75 0.3 0.566667
Dexter 0.76 0.0 0.25 0.1 0.300000
Band Of Brothers 0.89 0.0 0.50 0.4 0.933333
Mad Men 0.88 0.0 0.75 0.6 0.800000
[6]:
from mcda.mavt.aggregators import AHP
from pandas import DataFrame
[7]:
comparison_matrix = DataFrame(
    [
        [1, 2, 1/3, 1/4, 1/2],
        [1/2, 1, 1/2, 1/4, 1/2],
        [3, 2, 1, 1/5, 1/3],
        [4, 4, 5, 1, 2],
        [2, 2, 3, 1/2, 1]
    ],
    index=criteria,
    columns=criteria
)
comparison_matrix
[7]:
Critical Acclaim Awards Rewatchability Influence Consistency
Critical Acclaim 1.0 2 0.333333 0.25 0.500000
Awards 0.5 1 0.500000 0.25 0.500000
Rewatchability 3.0 2 1.000000 0.20 0.333333
Influence 4.0 4 5.000000 1.00 2.000000
Consistency 2.0 2 3.000000 0.50 1.000000
[8]:
ahp = AHP(comparison_matrix)
ahp
[8]:
AHP(criteria=['Critical Acclaim', 'Awards', 'Rewatchability', 'Influence', 'Consistency'], CR=0.076)
[9]:
ahp.criteria_weights
[9]:
Critical Acclaim    0.099222
Awards              0.081548
Rewatchability      0.135786
Influence           0.450058
Consistency         0.233386
dtype: float64
[10]:
ahp.criteria_weights.sum()
[10]:
1.0
[11]:
scores = ahp(normalize(performance_table))
scores.data
[11]:
Breaking Bad        0.753230
The Sopranos        0.842170
The Wire            0.769092
Better Call Saul    0.480442
Game Of Thrones     0.463828
Sherlock            0.452456
Dexter              0.224377
Band Of Brothers    0.554051
Mad Men             0.645898
dtype: float64
[12]:
scores.scale
[12]:
QuantitativeScale(interval=[0.22437681200610984, 0.8421697299220586])
[14]:
scores.sort().data
[14]:
The Sopranos        0.842170
The Wire            0.769092
Breaking Bad        0.753230
Mad Men             0.645898
Band Of Brothers    0.554051
Better Call Saul    0.480442
Game Of Thrones     0.463828
Sherlock            0.452456
Dexter              0.224377
dtype: float64
[ ]: