{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Critical AcclaimAwardsRewatchabilityInfluenceConsistency
Breaking Bad9716*****30.35
The Sopranos9221*****10.30
The Wire942****20.25
Better Call Saul870****80.40
Game Of Thrones8659***51.90
Sherlock849****71.30
Dexter764**92.10
Band Of Brothers896***60.20
Mad Men8816****40.60
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Critical AcclaimAwardsRewatchabilityInfluenceConsistency
Breaking Bad0.970.01.000.70.883333
The Sopranos0.920.01.000.90.900000
The Wire0.940.00.750.80.916667
Better Call Saul0.870.00.750.20.866667
Game Of Thrones0.860.00.500.50.366667
Sherlock0.840.00.750.30.566667
Dexter0.760.00.250.10.300000
Band Of Brothers0.890.00.500.40.933333
Mad Men0.880.00.750.60.800000
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Critical AcclaimAwardsRewatchabilityInfluenceConsistency
Critical Acclaim1.020.3333330.250.500000
Awards0.510.5000000.250.500000
Rewatchability3.021.0000000.200.333333
Influence4.045.0000001.002.000000
Consistency2.023.0000000.501.000000
\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 }