A Python package to implement TOPSIS
Project description
102303812-topsis
A Python package to implement TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) for multi-criteria decision analysis.
Author: Harsh Tanwar
Roll No: 102303812
Email: htanwar_be23@thapar.edu
Repository: Assignment1-Topsis
What is TOPSIS?
TOPSIS ranks alternatives by comparing each to an ideal positive and ideal negative solution. Alternatives closer to the ideal positive and farther from the ideal negative get higher scores and better ranks. The method uses vector normalization, weighted criteria, and Euclidean distances to compute a performance score for each alternative.
Requirements
- Python 3.6+
- pandas – data handling
- numpy – numerical operations
Install dependencies:
pip install pandas numpy
Installation
From PyPI (if published)
pip install 102303812-topsis
From source (clone or download the repo)
git clone https://github.com/htan11/course-materials.git
cd course-materials/UCS654/Assignment1-Topsis
pip install .
Or, in the folder containing setup.py:
pip install .
Usage
Command line
topsis <InputDataFile> <Weights> <Impacts> <OutputResultFileName>
Example (with 5 criteria):
topsis data.csv "1,1,1,1,1" "+,+,-,+,-" result.csv
As a Python module
(Because the package name contains a hyphen, use importlib to import.)
import importlib
topsis = getattr(importlib.import_module("102303812-topsis"), "topsis")
topsis("data.csv", "1,1,1,1,1", "+,+,-,+,-", "result.csv")
Parameters
| Parameter | Description |
|---|---|
| InputDataFile | Path to a CSV file: first column = alternative names, remaining columns = numeric criterion values. Must have a header row. |
| Weights | Comma-separated weights for each criterion (e.g. "1,1,1,2,1"). Number of values must match number of criteria. |
| Impacts | Comma-separated impacts: + for beneficial (higher is better), - for non-beneficial (lower is better). Same count as criteria. |
| OutputResultFileName | Path for the output CSV. Contains original columns plus Topsis Score and Rank. |
- Beneficial (
+): e.g. Quality, Customer Rating — higher value is better. - Non-beneficial (
-): e.g. Price, Delivery Time — lower value is better.
Input file format
CSV with a header; first column = alternative names, rest = numeric only.
Example (data.csv):
| Product | Quality | Price | Features | Customer Rating | Delivery Time |
|---|---|---|---|---|---|
| A1 | 8.5 | 450 | 7.2 | 4.3 | 3 |
| A2 | 7.8 | 380 | 8.1 | 4.5 | 5 |
| ... | ... | ... | ... | ... | ... |
- Column 1: labels (not used in math).
- Columns 2–6: criteria. Weights and impacts must be given for each of these in order.
Example with this dataset
For 5 criteria (Quality, Price, Features, Customer Rating, Delivery Time):
- Weights:
"1,1,1,1,1"(equal weight). - Impacts:
"+,+,-,+,-"(Quality +, Price +, Features -, Customer Rating +, Delivery Time -).
Run:
topsis data.csv "1,1,1,1,1" "+,+,-,+,-" result.csv
Output CSV will have all input columns plus:
- Topsis Score – higher is better.
- Rank – 1 = best alternative.
Output
The result file contains:
- All original columns.
- Topsis Score – performance score in [0, 1].
- Rank – integer rank (1 = best).
Example message: Result file 'result.csv' created successfully.
Project structure
assignment1_DS-main/
├── README.md
├── setup.py
├── data.csv # Sample input
├── 102303812-topsis/
│ ├── __init__.py
│ └── topsis.py # TOPSIS implementation
└── LICENSE
License
MIT License. See LICENSE for details.
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 Distribution
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 102303812_topsis-1.0.0.tar.gz.
File metadata
- Download URL: 102303812_topsis-1.0.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30e982f8c7785fefcb077827e391460c6ef3d6022e2ac8c563a7fd6a4161ee5a
|
|
| MD5 |
196fe7d543f9cb51bbbcd65900d8d3e6
|
|
| BLAKE2b-256 |
fe15c27629cf10cacb24f392bf2c4add24c0c90d64121302a7a8fefc4a5f3e2a
|
File details
Details for the file 102303812_topsis-1.0.0-py3-none-any.whl.
File metadata
- Download URL: 102303812_topsis-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb1d12c1feaaa9618844c73a9e9846a0f373401a28fb15231996a5a1a5978b8f
|
|
| MD5 |
11ac9cc4e8cdd89a4b3034a94b9f40dc
|
|
| BLAKE2b-256 |
9dbfad4d290593b07f1264d39f8a7f642a1bf8003234543f69875be3958b56ac
|