{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "9f5bd4eb",
"metadata": {},
"outputs": [],
"source": [
"%config Completer.use_jedi = True"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "82973705",
"metadata": {},
"outputs": [],
"source": [
"from mcda import PerformanceTable, normalize\n",
"from mcda.scales import QuantitativeScale, QualitativeScale, PreferenceDirection"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "92b9ee3f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Critical Acclaim | \n",
" Awards | \n",
" Rewatchability | \n",
" Influence | \n",
" Consistency | \n",
"
\n",
" \n",
" \n",
" \n",
" | Breaking Bad | \n",
" 97 | \n",
" 16 | \n",
" ***** | \n",
" 3 | \n",
" 0.35 | \n",
"
\n",
" \n",
" | The Sopranos | \n",
" 92 | \n",
" 21 | \n",
" ***** | \n",
" 1 | \n",
" 0.30 | \n",
"
\n",
" \n",
" | The Wire | \n",
" 94 | \n",
" 2 | \n",
" **** | \n",
" 2 | \n",
" 0.25 | \n",
"
\n",
" \n",
" | Better Call Saul | \n",
" 87 | \n",
" 0 | \n",
" **** | \n",
" 8 | \n",
" 0.40 | \n",
"
\n",
" \n",
" | Game Of Thrones | \n",
" 86 | \n",
" 59 | \n",
" *** | \n",
" 5 | \n",
" 1.90 | \n",
"
\n",
" \n",
" | Sherlock | \n",
" 84 | \n",
" 9 | \n",
" **** | \n",
" 7 | \n",
" 1.30 | \n",
"
\n",
" \n",
" | Dexter | \n",
" 76 | \n",
" 4 | \n",
" ** | \n",
" 9 | \n",
" 2.10 | \n",
"
\n",
" \n",
" | Band Of Brothers | \n",
" 89 | \n",
" 6 | \n",
" *** | \n",
" 6 | \n",
" 0.20 | \n",
"
\n",
" \n",
" | Mad Men | \n",
" 88 | \n",
" 16 | \n",
" **** | \n",
" 4 | \n",
" 0.60 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Critical Acclaim Awards Rewatchability Influence \\\n",
"Breaking Bad 97 16 ***** 3 \n",
"The Sopranos 92 21 ***** 1 \n",
"The Wire 94 2 **** 2 \n",
"Better Call Saul 87 0 **** 8 \n",
"Game Of Thrones 86 59 *** 5 \n",
"Sherlock 84 9 **** 7 \n",
"Dexter 76 4 ** 9 \n",
"Band Of Brothers 89 6 *** 6 \n",
"Mad Men 88 16 **** 4 \n",
"\n",
" Consistency \n",
"Breaking Bad 0.35 \n",
"The Sopranos 0.30 \n",
"The Wire 0.25 \n",
"Better Call Saul 0.40 \n",
"Game Of Thrones 1.90 \n",
"Sherlock 1.30 \n",
"Dexter 2.10 \n",
"Band Of Brothers 0.20 \n",
"Mad Men 0.60 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alternatives = [\n",
" \"Breaking Bad\", \"The Sopranos\", \"The Wire\",\n",
" \"Better Call Saul\", \"Game Of Thrones\", \"Sherlock\",\n",
" \"Dexter\", \"Band Of Brothers\", \"Mad Men\"\n",
"]\n",
"\n",
"scales = {\n",
" \"Critical Acclaim\": QuantitativeScale(0, 100),\n",
" \"Awards\": QuantitativeScale(0),\n",
" \"Rewatchability\": QualitativeScale({\"*\": 1, \"**\": 2, \"***\": 3, \"****\": 4, \"*****\": 5}),\n",
" \"Influence\": QuantitativeScale(0, 10, preference_direction=PreferenceDirection.MIN),\n",
" \"Consistency\": QuantitativeScale(0, 3, preference_direction=PreferenceDirection.MIN)\n",
"}\n",
"\n",
"criteria = list(scales.keys())\n",
"\n",
"performance_table = PerformanceTable(\n",
" [\n",
" [97, 16, \"*****\", 3, 0.35],\n",
" [92, 21, \"*****\", 1, 0.30],\n",
" [94, 2, \"****\", 2, 0.25],\n",
" [87, 0, \"****\", 8, 0.40],\n",
" [86, 59, \"***\", 5, 1.90],\n",
" [84, 9, \"****\", 7, 1.30],\n",
" [76, 4, \"**\", 9, 2.10],\n",
" [89, 6, \"***\", 6, 0.20],\n",
" [88, 16, \"****\", 4, 0.60]\n",
" ],\n",
" scales=scales,\n",
" alternatives=alternatives,\n",
" criteria=criteria,\n",
")\n",
"performance_table.data"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a325be07",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Critical Acclaim': QuantitativeScale(interval=[0, 100]),\n",
" 'Awards': QuantitativeScale(interval=[0, inf]),\n",
" 'Rewatchability': QualitativeScale(values={'*': 1, '**': 2, '***': 3, '****': 4, '*****': 5}),\n",
" 'Influence': QuantitativeScale(interval=[0, 10], preference_direction=PreferenceDirection.MIN),\n",
" 'Consistency': QuantitativeScale(interval=[0, 3], preference_direction=PreferenceDirection.MIN)}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"performance_table.scales"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f053f663",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Critical Acclaim | \n",
" Awards | \n",
" Rewatchability | \n",
" Influence | \n",
" Consistency | \n",
"
\n",
" \n",
" \n",
" \n",
" | Breaking Bad | \n",
" 0.97 | \n",
" 0.0 | \n",
" 1.00 | \n",
" 0.7 | \n",
" 0.883333 | \n",
"
\n",
" \n",
" | The Sopranos | \n",
" 0.92 | \n",
" 0.0 | \n",
" 1.00 | \n",
" 0.9 | \n",
" 0.900000 | \n",
"
\n",
" \n",
" | The Wire | \n",
" 0.94 | \n",
" 0.0 | \n",
" 0.75 | \n",
" 0.8 | \n",
" 0.916667 | \n",
"
\n",
" \n",
" | Better Call Saul | \n",
" 0.87 | \n",
" 0.0 | \n",
" 0.75 | \n",
" 0.2 | \n",
" 0.866667 | \n",
"
\n",
" \n",
" | Game Of Thrones | \n",
" 0.86 | \n",
" 0.0 | \n",
" 0.50 | \n",
" 0.5 | \n",
" 0.366667 | \n",
"
\n",
" \n",
" | Sherlock | \n",
" 0.84 | \n",
" 0.0 | \n",
" 0.75 | \n",
" 0.3 | \n",
" 0.566667 | \n",
"
\n",
" \n",
" | Dexter | \n",
" 0.76 | \n",
" 0.0 | \n",
" 0.25 | \n",
" 0.1 | \n",
" 0.300000 | \n",
"
\n",
" \n",
" | Band Of Brothers | \n",
" 0.89 | \n",
" 0.0 | \n",
" 0.50 | \n",
" 0.4 | \n",
" 0.933333 | \n",
"
\n",
" \n",
" | Mad Men | \n",
" 0.88 | \n",
" 0.0 | \n",
" 0.75 | \n",
" 0.6 | \n",
" 0.800000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Critical Acclaim Awards Rewatchability Influence \\\n",
"Breaking Bad 0.97 0.0 1.00 0.7 \n",
"The Sopranos 0.92 0.0 1.00 0.9 \n",
"The Wire 0.94 0.0 0.75 0.8 \n",
"Better Call Saul 0.87 0.0 0.75 0.2 \n",
"Game Of Thrones 0.86 0.0 0.50 0.5 \n",
"Sherlock 0.84 0.0 0.75 0.3 \n",
"Dexter 0.76 0.0 0.25 0.1 \n",
"Band Of Brothers 0.89 0.0 0.50 0.4 \n",
"Mad Men 0.88 0.0 0.75 0.6 \n",
"\n",
" Consistency \n",
"Breaking Bad 0.883333 \n",
"The Sopranos 0.900000 \n",
"The Wire 0.916667 \n",
"Better Call Saul 0.866667 \n",
"Game Of Thrones 0.366667 \n",
"Sherlock 0.566667 \n",
"Dexter 0.300000 \n",
"Band Of Brothers 0.933333 \n",
"Mad Men 0.800000 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"normalize(performance_table).data"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7e69035d",
"metadata": {},
"outputs": [],
"source": [
"from mcda.mavt.aggregators import AHP\n",
"from pandas import DataFrame"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "d803105d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Critical Acclaim | \n",
" Awards | \n",
" Rewatchability | \n",
" Influence | \n",
" Consistency | \n",
"
\n",
" \n",
" \n",
" \n",
" | Critical Acclaim | \n",
" 1.0 | \n",
" 2 | \n",
" 0.333333 | \n",
" 0.25 | \n",
" 0.500000 | \n",
"
\n",
" \n",
" | Awards | \n",
" 0.5 | \n",
" 1 | \n",
" 0.500000 | \n",
" 0.25 | \n",
" 0.500000 | \n",
"
\n",
" \n",
" | Rewatchability | \n",
" 3.0 | \n",
" 2 | \n",
" 1.000000 | \n",
" 0.20 | \n",
" 0.333333 | \n",
"
\n",
" \n",
" | Influence | \n",
" 4.0 | \n",
" 4 | \n",
" 5.000000 | \n",
" 1.00 | \n",
" 2.000000 | \n",
"
\n",
" \n",
" | Consistency | \n",
" 2.0 | \n",
" 2 | \n",
" 3.000000 | \n",
" 0.50 | \n",
" 1.000000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Critical Acclaim Awards Rewatchability Influence \\\n",
"Critical Acclaim 1.0 2 0.333333 0.25 \n",
"Awards 0.5 1 0.500000 0.25 \n",
"Rewatchability 3.0 2 1.000000 0.20 \n",
"Influence 4.0 4 5.000000 1.00 \n",
"Consistency 2.0 2 3.000000 0.50 \n",
"\n",
" Consistency \n",
"Critical Acclaim 0.500000 \n",
"Awards 0.500000 \n",
"Rewatchability 0.333333 \n",
"Influence 2.000000 \n",
"Consistency 1.000000 "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"comparison_matrix = DataFrame(\n",
" [\n",
" [1, 2, 1/3, 1/4, 1/2],\n",
" [1/2, 1, 1/2, 1/4, 1/2],\n",
" [3, 2, 1, 1/5, 1/3],\n",
" [4, 4, 5, 1, 2],\n",
" [2, 2, 3, 1/2, 1]\n",
" ],\n",
" index=criteria,\n",
" columns=criteria\n",
")\n",
"comparison_matrix"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ef254f50",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AHP(criteria=['Critical Acclaim', 'Awards', 'Rewatchability', 'Influence', 'Consistency'], CR=0.076)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ahp = AHP(comparison_matrix)\n",
"ahp"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "2a262d37",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Critical Acclaim 0.099222\n",
"Awards 0.081548\n",
"Rewatchability 0.135786\n",
"Influence 0.450058\n",
"Consistency 0.233386\n",
"dtype: float64"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ahp.criteria_weights"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "7f60b9e9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ahp.criteria_weights.sum()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "cf6f5401",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Breaking Bad 0.753230\n",
"The Sopranos 0.842170\n",
"The Wire 0.769092\n",
"Better Call Saul 0.480442\n",
"Game Of Thrones 0.463828\n",
"Sherlock 0.452456\n",
"Dexter 0.224377\n",
"Band Of Brothers 0.554051\n",
"Mad Men 0.645898\n",
"dtype: float64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scores = ahp(normalize(performance_table))\n",
"scores.data"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "07975b2c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QuantitativeScale(interval=[0.22437681200610984, 0.8421697299220586])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scores.scale"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "7d5ed30c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"The Sopranos 0.842170\n",
"The Wire 0.769092\n",
"Breaking Bad 0.753230\n",
"Mad Men 0.645898\n",
"Band Of Brothers 0.554051\n",
"Better Call Saul 0.480442\n",
"Game Of Thrones 0.463828\n",
"Sherlock 0.452456\n",
"Dexter 0.224377\n",
"dtype: float64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scores.sort().data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f82ad811",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}