Skip to main content

A Python module for TOPSIS analysis

Project description

TOPSIS Analysis Package

This Python package implements the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) analysis. The package is designed to facilitate the execution of TOPSIS analysis on input data using a command-line interface.

Usage

To utilize the TOPSIS analysis, follow these steps:

1. Program Structure and Imports:

  • The package structure is as follows:
    • Imports:
      • pandas for data manipulation.
      • normalize from sklearn.preprocessing for data normalization.
      • LabelEncoder from sklearn.preprocessing for encoding categorical columns.
      • warnings for handling warnings.
      • sys for command-line arguments.

2. Extracting Data from Command Line:

  • Command-line arguments are extracted, including the input file path, weights, impacts, and the desired result file name. An error message is displayed if the correct number of arguments is not provided.

3. Reading Input Data:

  • The input Excel file is read using pandas, with the 'Fund Name' column set as the index. If the file is not found, an error message is displayed, and the program exits.

4. Validate Input Data:

  • The script checks if the input data meets certain criteria:
    • The input file must contain three or more columns.
    • Columns, excluding the 'Fund Name' index, should contain only numeric values.
    • The number of weights, impacts, and columns (excluding the index) must be the same.
    • Impacts must be either '+' or '-'.

5. Convert Categorical Columns to Numerical:

  • If there are categorical columns in the input data, they are encoded using the LabelEncoder from scikit-learn.

6. Normalization:

  • The input data is normalized using the sklearn normalize function. Each column is normalized based on the specified weights.

7. Finding Ideal Best and Ideal Worst:

  • Ideal best and ideal worst values are determined for each column based on the specified impacts ('+' or '-'). Ideal best values are the maximum values for '+' impacts, and ideal worst values are the minimum values.

8. Calculating Euclidean Distance:

  • Euclidean distances (splus and sminus) are computed for each row, representing the similarity to ideal solutions (best and worst).

9. Calculate Performance Score:

  • The performance score is calculated for each row based on the formula: sminus / (sminus + splus).

10. Assign Rank:

  • Each row is assigned a rank based on its performance score, with lower scores receiving higher ranks.

11. Appending Results to Original DataFrame:

  • The Topsis Score and Rank columns are appended to the original DataFrame.

12. Save the Result DataFrame to a CSV File:

  • The resulting DataFrame, including Topsis Score and Rank columns, is saved to a CSV file specified in the command-line arguments.

Execution

To execute the package, run the script from the command line, providing the required input parameters in the following order:

python program.py <InputDataFile> <Weights> <Impacts> <ResultFileName>

Ensure the correct number of parameters, handle file not found exceptions, and adhere to the specified input file format. The resulting DataFrame with Topsis Score and Rank columns will be saved in a CSV file.

Note: Make sure to install the required libraries before running the program using the following:

pip install pandas scikit-learn

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Topsis-Maninder-102153010-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Topsis_Maninder_102153010-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file Topsis-Maninder-102153010-0.0.1.tar.gz.

File metadata

File hashes

Hashes for Topsis-Maninder-102153010-0.0.1.tar.gz
Algorithm Hash digest
SHA256 127e42b83b48a33584136d9c71b6fddc6bfe253e29812c2a6589b638bc824e2f
MD5 8bd0c5c7635f0c02e2c3c05eccfbe4fe
BLAKE2b-256 6141dbc707a65f4c6827afbc401e8dd9a562ab94e807e13bf906c9a30b091516

See more details on using hashes here.

File details

Details for the file Topsis_Maninder_102153010-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for Topsis_Maninder_102153010-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 176a75e82e9f7557cfa4673d11c2aaf369a186981c7abc40493a6af05b98b37e
MD5 fb55dbb425756861482fe08eb7cfc14e
BLAKE2b-256 ee7037f9a420293d92e0eb2fd95514e6d573a5a2d5d3c58a7a4327d44f824c78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page