A Python implementation of the TOPSIS
Project description
TOPSIS (Technique for Order Preference by Similarity to Ideal Solution)
Overview
TOPSIS - This is a method which we can use to make decisions if we have multiple parameters from which we have to decide which model to choose by giving weights(preference) to those parameters and maximising or minimising them.
Features
- Supports CSV input files.
- Handles numeric validation for criteria columns.
- Accepts weights and impacts for criteria.
- Detailed error messages for invalid inputs.
- Outputs the TOPSIS score and rank for each alternative.
Installation
pip install 102203594_topsis
Usage
Input Requirements
-
Input File: A CSV file containing the decision matrix.
- The first column should contain the names of the alternatives.
- Remaining columns should contain numeric values for the criteria.
-
Weights: A list of numeric values representing the weight of each criterion.
- Must match the number of criteria columns in the dataset.
-
Impacts: A list of strings (
'up'or'down') indicating whether higher or lower values are better for each criterion.- Must match the number of criteria columns in the dataset.
Example Input File
File: data.csv
Alternative,Criterion 1,Criterion 2,Criterion 3
Model-1,250,16,12
Model-2,200,16,8
Model-3,300,32,16
Model-4,275,32,8
Model-5,225,16,16
Example Code
from topsis import topsis
# Define weights and impacts
weights = [0.25, 0.25, 0.25]
impacts = ['up', 'up', 'down']
# Perform TOPSIS
try:
result = topsis("data.csv", weights, impacts)
print(result)
except Exception as e:
print(f"Error: {e}")
Output
The output is a DataFrame containing the original data with two additional columns:
- Topsis Score: The relative closeness to the ideal solution.
- Rank: The rank of each alternative based on the TOPSIS score.
Example Output:
Alternative Criterion 1 Criterion 2 Criterion 3 Topsis Score Rank
0 Model-1 250 16 12 0.534522 3
1 Model-2 200 16 8 0.308607 5
2 Model-3 300 32 16 0.780869 1
3 Model-4 275 32 8 0.612372 2
4 Model-5 225 16 16 0.199736 4
Error Handling
The package includes robust error handling for:
- File Format: Ensures the input file is a
.csvfile. - Missing File: Handles missing or incorrect file paths.
- Empty File: Raises an error if the input file is empty.
- Column Validation:
- Ensures at least one column for alternatives and one for criteria.
- Checks that all criteria columns contain numeric values.
- Weights and Impacts:
- Ensures weights and impacts match the number of criteria.
- Validates that impacts are either
'up'or'down'.
Authors
- Your Name - Your GitHub Profile
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 102203594_topsis-0.1.0.tar.gz.
File metadata
- Download URL: 102203594_topsis-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d575d33bbcab47752b6fa9272611a23b0b9bb68c1aa21c51b16d872637384a4b
|
|
| MD5 |
1745813941c7006ecaf4133c32384b8a
|
|
| BLAKE2b-256 |
b08554efa85b877e97f34b05205eb5bd295ef95d9959147a64719832a485e605
|
File details
Details for the file 102203594_topsis-0.1.0-py3-none-any.whl.
File metadata
- Download URL: 102203594_topsis-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cb3af4ea8634320c8485ca36f4d072f9186991e3f6bf047c8549f2c6718de8f
|
|
| MD5 |
ed3d77dfe2d8d4574c2ab3d140fe8e23
|
|
| BLAKE2b-256 |
66b39360598e9f271734ac8273cd158f2147bce8d67caed68fafc2f230c4bbb7
|