-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Simple TOPSIS example\n", | ||
"\n", | ||
"Let make a simple topsis example" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from skcriteria import topsis" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"- Every candidate will be a posible alternative inside the method. I call every alternative as A1, A2...\n", | ||
"- Every alternative has the same set of criteria C1, C2...\n", | ||
"- Every criteria represent a numerical value of some measuremente of some characteristic of the alternative\n", | ||
" for example Age, If they has talks or not, how far away of the venue they live, etc.\n", | ||
"- Every criteria can be maximized or minimiszed but not the two of them.\n", | ||
"\n", | ||
"For example:\n", | ||
"\n", | ||
"- **Ivan:** Speaker, Lives in Floripa, Give a talk last year\n", | ||
"- **Raniere:** Speaker, Lives in Campinhas, Give a talk last year\n", | ||
"- **Juan:** Not Speaker, Lives in Cordoba, Not Give a talk last year\n", | ||
"\n", | ||
"The first criteria is a float equals to how many hours they gona talk in the conference (tlaks increment 1 and tutotiral increments 3)\n", | ||
"Now if we think the distance between where they live and where is the venue we can have the second criteria.\n", | ||
"The last one is a boollean (1: they give a talk in scipy2015, 0: Nope)\n", | ||
"\n", | ||
"So the matrix is like" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"mtx = [\n", | ||
" [1., 0., 1], # ivan\n", | ||
" [4, 770., 1], # raniere\n", | ||
" [0, 1885., 0], # juan\n", | ||
"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now we need the criteria:\n", | ||
" - Is better to to give more hours of talk (maximization criteria)\n", | ||
" - Is better to be away from the vennue (maximization)\n", | ||
" - Is better to give a talk the last year (max)\n", | ||
" \n", | ||
"So the criteria array must be like" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"criteria = [1, 1, 1] # minimization is '-1'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The last thing is give a series of weight of every criteria (this is optional) for example we can think that the first criteria have the 45% of importance, the second criteria the 40% and the last one only the 15%" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"weights = [45, 40, 15]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now lets apply [TOPSIS](https://en.wikipedia.org/wiki/TOPSIS)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"rank, points = topsis.topsis(mtx, criteria, weights)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The `rank` variable contains the ranking of every order alternative and the `points` is the distance of every alternative to the ideal and anti-ideal points (read this for understand topsis: https://en.wikipedia.org/wiki/TOPSIS)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 17, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"1 raniere\n", | ||
"2 juan\n", | ||
"3 ivan\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for r, name in sorted(zip(rank, [\"ivan\", \"raniere\", \"juan\"])):\n", | ||
" print r, name" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.5+" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |