Created
April 23, 2022 16:26
-
-
Save leliel12/918c4b3d023b64a3cd088df19d5c6120 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "## How to merge multiple ranks into a single dataframe" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import skcriteria as skc" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div class=\"decisionmatrix\">\n", | |
| "<div>\n", | |
| "<style scoped=\"\">\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th/>\n", | |
| " <th>autonomy[▲ 1.0]</th>\n", | |
| " <th>comfort[▲ 1.0]</th>\n", | |
| " <th>price[▲ 1.0]</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>car 0</th>\n", | |
| " <td>1</td>\n", | |
| " <td>2</td>\n", | |
| " <td>3</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>car 1</th>\n", | |
| " <td>4</td>\n", | |
| " <td>5</td>\n", | |
| " <td>6</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div><em class=\"decisionmatrix-dim\">2 Alternatives x 3 Criteria</em>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " autonomy[▲ 1.0] comfort[▲ 1.0] price[▲ 1.0]\n", | |
| "car 0 1 2 3\n", | |
| "car 1 4 5 6\n", | |
| "[2 Alternatives x 3 Criteria]" | |
| ] | |
| }, | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "dm = skc.mkdm(\n", | |
| " matrix=[\n", | |
| " [1, 2, 3], # alternative 1\n", | |
| " [4, 5, 6], # alternative 2\n", | |
| " ],\n", | |
| " objectives=[max, max, max],\n", | |
| " alternatives=[\"car 0\", \"car 1\"],\n", | |
| " criteria=[\"autonomy\", \"comfort\", \"price\"],\n", | |
| ")\n", | |
| "dm\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "## Create two ranks with two methods" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from skcriteria.madm import simple" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div class='skcresult-rank skcresult'>\n", | |
| "<style type=\"text/css\">\n", | |
| "</style>\n", | |
| "<table id=\"T_596ab\">\n", | |
| " <thead>\n", | |
| " <tr>\n", | |
| " <th class=\"blank level0\" > </th>\n", | |
| " <th id=\"T_596ab_level0_col0\" class=\"col_heading level0 col0\" >car 0</th>\n", | |
| " <th id=\"T_596ab_level0_col1\" class=\"col_heading level0 col1\" >car 1</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th id=\"T_596ab_level0_row0\" class=\"row_heading level0 row0\" >Rank</th>\n", | |
| " <td id=\"T_596ab_row0_col0\" class=\"data row0 col0\" >2</td>\n", | |
| " <td id=\"T_596ab_row0_col1\" class=\"data row0 col1\" >1</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "<em class='skcresult-method'>Method: WeightedSumModel</em>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " car 0 car 1\n", | |
| "Rank 2 1\n", | |
| "[Method: WeightedSumModel]" | |
| ] | |
| }, | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "rank0 = simple.WeightedSumModel().evaluate(dm)\n", | |
| "rank0" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div class='skcresult-rank skcresult'>\n", | |
| "<style type=\"text/css\">\n", | |
| "</style>\n", | |
| "<table id=\"T_6e026\">\n", | |
| " <thead>\n", | |
| " <tr>\n", | |
| " <th class=\"blank level0\" > </th>\n", | |
| " <th id=\"T_6e026_level0_col0\" class=\"col_heading level0 col0\" >car 0</th>\n", | |
| " <th id=\"T_6e026_level0_col1\" class=\"col_heading level0 col1\" >car 1</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th id=\"T_6e026_level0_row0\" class=\"row_heading level0 row0\" >Rank</th>\n", | |
| " <td id=\"T_6e026_row0_col0\" class=\"data row0 col0\" >2</td>\n", | |
| " <td id=\"T_6e026_row0_col1\" class=\"data row0 col1\" >1</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "<em class='skcresult-method'>Method: WeightedProductModel</em>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " car 0 car 1\n", | |
| "Rank 2 1\n", | |
| "[Method: WeightedProductModel]" | |
| ] | |
| }, | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "rank1 = simple.WeightedProductModel().evaluate(dm)\n", | |
| "rank1" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 13, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<style scoped>\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th>WeightedSumModel</th>\n", | |
| " <th>WeightedProductModel</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0</th>\n", | |
| " <td>2</td>\n", | |
| " <td>2</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>1</th>\n", | |
| " <td>1</td>\n", | |
| " <td>1</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " WeightedSumModel WeightedProductModel\n", | |
| "0 2 2\n", | |
| "1 1 1" | |
| ] | |
| }, | |
| "execution_count": 13, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "pd.DataFrame({rank0.method: rank0.values, rank1.method: rank1.values})" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "interpreter": { | |
| "hash": "bb4160009357201beaf583af3fb6532839cedbd2b920c61e4caa741a05856261" | |
| }, | |
| "kernelspec": { | |
| "display_name": "Python 3.9.7 ('skcriteria')", | |
| "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.9.7" | |
| }, | |
| "orig_nbformat": 4 | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment