Juan B Cabral – Bruno O Sanchez – Manuel Starck Cuffini
Instituto de Astronomía Teórica y Experimental
jbcabral@oac.unc.edu.ar- bruno@oac.unc.edu.ar- mstarck@oac.unc.edu.ar
In [1]:
import pandas as pd
import numpy as np
import skcriteria as sc
from skcriteria.madm import topsis, wsum, moora, wprod, electre
In [2]:
df = pd.read_csv("sites.csv")[:-3]
df
Out[2]:
In [3]:
anames = df.columns[2:].values
def to_apply(r):
new = []
for e in r:
if isinstance(e , str):
e = float(e.replace("*", ""))
new.append(e)
return new
mtx = df[anames][3:].dropna()[anames].apply(to_apply).T.values
criteria = [sc.MIN if c == "min" else sc.MAX for c in df.Criteria[3:][~df.Armazones.isnull()].values]
cnames = df["Criteria/Alternatives"][3:].apply(lambda r: r.strip())[~df[3:].Armazones.isnull()].values
cnames = map(lambda s: s.decode("utf8"), cnames)
data = sc.Data(mtx, criteria, anames=anames, cnames=cnames)
In [4]:
data
Out[4]:
In [5]:
dm = topsis.TOPSIS()
topsis_dec = dm.decide(data)
topsis_dec
Out[5]:
In [6]:
dm = wsum.MDWeightedSum()
wsum_dec = dm.decide(data)
wsum_dec
Out[6]:
In [7]:
dm = wprod.WeightedProduct()
wprod_dec = dm.decide(data)
wprod_dec
Out[7]:
In [8]:
dm = electre.ELECTRE1()
electre_dec = dm.decide(data)
electre_dec
Out[8]:
In [9]:
methods = ["TOPSIS", "WSUM", "WPROD"]
kernel = np.array([1 if idx in electre_dec.kernel_ else 0 for idx, _ in enumerate(anames)])
ranks = np.vstack((topsis_dec.rank_, wsum_dec.rank_, wprod_dec.rank_, kernel)).T
rdf = pd.DataFrame(ranks, index=anames, columns=methods + ["ELECTRE 1 Kernel"])
rdf
Out[9]:
In [10]:
rdf[methods].T.describe()
Out[10]: