A python package to implement TOPSIS on a given dataset
Project description
TOPSIS-Python
Submitted By: Niyati Kapoor
Roll Number: 102003732
Batch: 3COE23
pypi: https://pypi.org/project/Topsis-Niyati-102003732
Installation
pip install Topsis-Niyati-102003732
What is TOPSIS
TOPSIS or Technique for Order Preference by Similarity to Ideal Solution is a method of compensatory aggregation that compares a set of alternatives by identifying weights for each criterion, normalising scores for each criterion and calculating the geometric distance between each alternative and the ideal alternative, which is the best score in each criterion
How to use this package:
Topsis-Niyati-102003732 can be run as in the following example:
In Command Prompt
>> topsis input.csv "1,1,1,1,1" "+,+,-,+,+" output.csv
Process
First we create an evaluation matrix which consists of m alternatives and n criterias, with the intersection of each alternative and criteria. Then we move to the preprocessing phase. We then normalize the matrix using norm. Weighted normalised decision matrix is then calculated. We then determine the best and worst alternatives. After that, we calculate the euclidean distance between the target alternative and the worst condition. Finally, the similarity to the worst condition checked and the alternatives are ranked according to the final performance scores, awarding lower rank to higher performance score.
Sample dataset
Consider this sample.csv file
First column of file is removed by model before processing so follow the following format.
All other columns of file should not contain any categorical values.
| Model | P1 | P2 | P3 | P4 | P5 |
|---|---|---|---|---|---|
| M1 | 0.85 | 0.72 | 4.6 | 41.5 | 11.92 |
| M2 | 0.66 | 0.44 | 6.6 | 49.4 | 14.28 |
| M3 | 0.9 | 0.81 | 6.7 | 66.5 | 18.73 |
| M4 | 0.8 | 0.64 | 6.9 | 69.7 | 19.51 |
| M5 | 0.84 | 0.71 | 4.7 | 36.5 | 10.69 |
| M6 | 0.91 | 0.83 | 3.6 | 42.3 | 11.91 |
| M7 | 0.65 | 0.42 | 6.9 | 38.1 | 11.52 |
| M8 | 0.71 | 0.5 | 3.5 | 60.9 | 16.4 |
weights vector = [ 1,2,1,2,1 ]
impacts vector = [ +,-,+,+,- ]
input:
topsis input.csv "1,2,1,2,1" "+,-,+,+,-" output.csv
output:
output.csv file will contain following data :
| Model | P1 | P2 | P3 | P4 | P5 | Topsis score | Rank |
|---|---|---|---|---|---|---|---|
| M1 | 0.85 | 0.72 | 4.6 | 41.5 | 11.92 | 0.3267076760116426 | 6 |
| M2 | 0.66 | 0.44 | 6.6 | 49.4 | 14.28 | 0.6230956090525585 | 2 |
| M3 | 0.9 | 0.81 | 6.7 | 66.5 | 18.73 | 0.5006083702087599 | 5 |
| M4 | 0.8 | 0.64 | 6.9 | 69.7 | 19.51 | 0.6275096427934269 | 1 |
| M5 | 0.84 | 0.71 | 4.7 | 36.5 | 10.69 | 0.3249142875298663 | 7 |
| M6 | 0.91 | 0.83 | 3.6 | 42.3 | 11.91 | 0.2715902624653612 | 8 |
| M7 | 0.65 | 0.42 | 6.9 | 38.1 | 11.52 | 0.5439263412940541 | 4 |
| M8 | 0.71 | 0.5 | 3.5 | 60.9 | 16.4 | 0.6166791918077927 | 3 |
The decision matrix (a) should be constructed with each row representing a Model alternative, and each column representing a criterion like Accuracy, R2, Root Mean Squared Error, Correlation, and many more.
Weights (w) is not already normalised will be normalised later in the code.
Information of benefit positive(+) or negative(-) impact criteria should be provided in I.
The rankings are stored in a csv file, with the 1st rank offering us the best decision, and last rank offering the worst decision making, according to TOPSIS method.
Debugging and Exception Handling
The program has several assert statements which raise errors with helpful description in the following cases:
- Wrong dimensions of decision matrix (not 2D), weights (not 1D)
- Length of weights and impacts don't match
- Weights or impacts don't match number of attributes
- For command line, number of arguments is less than 3 required
- File extension must be .csv
License
Copyright 2023 Niyati Kapoor
This repository is licensed under the MIT license.
See LICENSE for details.
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Topsis_Niyati_102003732-0.0.0-py3-none-any.whl.
File metadata
- Download URL: Topsis_Niyati_102003732-0.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e715ef28206f578a5b0d008fb5b221f24e4294b55ad59e5a7394dd3c832c38ed
|
|
| MD5 |
1266d3862520d956135d8be59be0ce7c
|
|
| BLAKE2b-256 |
a20913535c78507a6663af36350c647b66a32586ace79e1884be8991878b88c8
|