TOPSIS multi-criteria decision making — CLI tool with sensitivity dashboard
Project description
Topsis-Anvvi-102317133
A Python package implementing the TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) multi-criteria decision analysis method. Supports CSV and Excel input, automatic ordinal encoding, null handling, and an optional interactive sensitivity analysis dashboard.
Table of Contents
- Installation
- Method Overview
- Command-Line Usage
- Input File Format
- Ordinal Encoding
- Null Handling
- Output Format
- Sensitivity Analysis Dashboard
- Programmatic API
- Requirements
- License
Installation
pip install Topsis-Anvvi-102317133
Method Overview
TOPSIS ranks a set of alternatives by measuring how close each one is to an ideal best solution and how far it is from an ideal worst solution. The algorithm proceeds as follows:
- Normalise the decision matrix using Euclidean (column-wise) normalisation
- Apply weights to produce a weighted normalised matrix
- Determine the ideal best and ideal worst vectors, respecting each criterion's impact direction (
+beneficial,-cost) - Compute Euclidean distances from each alternative to both ideal vectors
- Calculate the TOPSIS score — a value in [0, 1] where higher is better:
Score(i) = dist_worst(i) / (dist_best(i) + dist_worst(i))
- Rank alternatives by score in descending order
Command-Line Usage
topsis <InputFile> <Weights> <Impacts> <ResultFile> [--sensitivity]
Arguments
| Argument | Type | Description |
|---|---|---|
InputFile |
str |
Path to input .csv or .xlsx file |
Weights |
str |
Comma-separated positive numbers e.g. "1,1,2,1" |
Impacts |
str |
Comma-separated + or - signs e.g. "+,+,-,+" |
ResultFile |
str |
Path for output .csv or .xlsx file |
--sensitivity |
flag | Optional — generates an interactive HTML dashboard |
Examples
# Basic usage
topsis data.csv "1,1,2,1" "+,+,-,+" result.csv
# With sensitivity dashboard
topsis data.csv "1,1,2,1" "+,+,-,+" result.csv --sensitivity
# Excel input and output
topsis data.xlsx "1,1,2,1" "+,+,-,+" result.xlsx --sensitivity
Input File Format
The input file must follow this structure:
- Column 1 — Alternative names (any string label)
- Columns 2 onward — Criteria values (numeric, or ordinal text — see below)
- The number of criteria columns must equal the number of weights and impacts provided
Sample Input (data.csv)
| Model | Cost ($) | Storage (GB) | Camera (MP) | Battery | Rating |
|---|---|---|---|---|---|
| M1 | 250 | 16 | 12 | 5000 | good |
| M2 | 200 | 32 | 13 | 3000 | poor |
| M3 | 300 | 32 | 12 | 3500 | good |
| M4 | 275 | 32 | 17 | 2500 | average |
| M5 | 225 | 16 | 13 | 4800 | excellent |
topsis data.csv "1,1,1,1,1" "-,+,+,+,+" result.csv
Cost has impact - (lower is better). All others have impact + (higher is better). The text column Rating is automatically encoded.
Ordinal Encoding
Non-numeric text columns are automatically detected and encoded to integers if they match a known ordinal scale:
| Level | Scale Values | Encoded As |
|---|---|---|
| 2 | no, yes |
0, 1 |
| 2 | false, true |
0, 1 |
| 3 | low, medium, high |
1, 2, 3 |
| 3 | bad, moderate, good |
1, 2, 3 |
| 3 | poor, average, good |
1, 2, 3 |
| 3 | weak, moderate, strong |
1, 2, 3 |
| 3 | small, medium, large |
1, 2, 3 |
| 4 | poor, average, good, excellent |
1, 2, 3, 4 |
| 4 | low, medium, high, very high |
1, 2, 3, 4 |
| 5 | very bad, bad, moderate, good, very good |
1, 2, 3, 4, 5 |
| 5 | very low, low, medium, high, very high |
1, 2, 3, 4, 5 |
| 5 | very poor, poor, average, good, excellent |
1, 2, 3, 4, 5 |
Matching is case-insensitive and trims whitespace. If a column contains text that doesn't match any known scale, the program exits with a descriptive error.
Null Handling
Missing values are handled automatically before computation:
- Rows where all criteria are null — dropped entirely, with a warning printed
- Numeric columns with nulls — filled with the column mean
- Text columns with nulls — filled with the column mode
All substitutions are reported to stdout.
Output Format
The result file contains all original columns plus two appended columns:
| Model | Cost ($) | ... | Topsis Score | Rank |
|---|---|---|---|---|
| M5 | 225 | ... | 0.7623 | 1 |
| M1 | 250 | ... | 0.6891 | 2 |
| M3 | 300 | ... | 0.5340 | 3 |
| M4 | 275 | ... | 0.4102 | 4 |
| M2 | 200 | ... | 0.2987 | 5 |
- Topsis Score — float in [0, 1]; higher = better
- Rank — integer; 1 = best; ties share the same rank (dense ranking)
Sensitivity Analysis Dashboard
When --sensitivity is passed, a self-contained HTML file is generated alongside the result (e.g. result_sensitivity.html). Open it in any browser — no server required.
Features
- Live weight sliders — adjust each criterion's weight in real time; rankings update instantly
- Score bars — visual comparison of TOPSIS scores across all alternatives
- Rank delta badges — shows how many positions each alternative moved from the original ranking
- Sweep analysis chart — plots how every alternative's rank changes as one criterion's weight is swept from 0 → 5, while all others are held fixed
- Natural-language insight — auto-generated summary of the most significant rank change observed
Interpreting the sweep chart
A flat horizontal line means an alternative's rank is robust to changes in that criterion. Crossing lines indicate rank reversals — points where two alternatives swap positions as the weight shifts.
Programmatic API
TOPSIS can also be called directly from Python:
from Topsis_Anvvi_102317133.Topsiss import topsis
result_df = topsis(
input_file = "data.csv",
weights_str = "1,1,2,1",
impacts_str = "+,+,-,+",
result_file = "result.csv",
sensitivity = True # False to skip dashboard
)
print(result_df[["Topsis Score", "Rank"]])
The function returns the result DataFrame directly, in addition to writing it to disk.
Requirements
| Package | Minimum Version |
|---|---|
| Python | 3.7+ |
| pandas | 1.3.0 |
| numpy | 1.21.0 |
| openpyxl | 3.0.0 |
License
MIT License — free to use, modify, and distribute.
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 topsis_anvvi_102317133-1.0.0.tar.gz.
File metadata
- Download URL: topsis_anvvi_102317133-1.0.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30d040fc4c8132cfe32135b1384f2b555119fb185320a4ceae211d173bd05746
|
|
| MD5 |
b352f0787c46f92afd5306b9ce340757
|
|
| BLAKE2b-256 |
6c3dad725359275d182c63d61ff50937c4224aeb42eec0409f61dd0337a0231d
|
File details
Details for the file topsis_anvvi_102317133-1.0.0-py3-none-any.whl.
File metadata
- Download URL: topsis_anvvi_102317133-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18b27b997aa7118f63ed7c159191ec20a69a6f9aedc17ee4352eab34b9528684
|
|
| MD5 |
251722b82bf2cab5e99f0e091e65c67c
|
|
| BLAKE2b-256 |
36144627e5f660abc5f1634654791364771a4d380ae3c03c9aac106b628022ec
|