Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PCA Tool - simple wrapper to manage PCA easily

Overview

PCA_tool.py is a Python wrapper module for performing Principal Component Analysis (PCA) on datasets. This tool is designed for exploratory data analysis, allowing users to investigate data structure, dimensionality reduction, and variable relationships.

The tool provides functionalities for data scaling, PCA computation, visualization, and export of results. It supports continuous and discrete target variables for enhanced analysis.


Features

  • Autoscaling: Standardizes the dataset for PCA.
  • PCA Computation: Computes PCA components, eigenvalues, explained variance, and loadings.
  • Data Export: Saves PCA results, including scores, eigenvalues, explained variance, and loadings, to an Excel file.
  • Visualization:
    • Scree plot for explained variance analysis.
    • Loadings plot to understand variable contributions.
    • Scatter plot of PCA scores with optional color coding by target variable.
  • Customizability:
    • Adjust visualization parameters such as the number of components, color thresholds, and marker sizes.
    • Choose whether to scale data before PCA.

Installation

  1. Clone or download the repository.
  2. Ensure the required Python packages are installed:
    pip install pandas scikit-learn matplotlib numpy

Usage

Import the Module

from PCA_tool import PCA_tool

Initialize with Data

import pandas as pd

# Example datasets
df_x = pd.read_csv('input_features.csv', index_col=0)  # Feature dataset
df_y = pd.read_csv('target_labels.csv', index_col=0)  # Optional target variable

# Initialize PCA tool
pca = PCA_tool(df_x, df_y)

Perform PCA

pca.perform_pca(scale=True)  # Set `scale=False` to skip autoscaling

Save Results

pca.save_data(filename='pca_results')

Visualizations

Scree Plot

pca.plot_scree(num_pcs=10, save=True)

Loadings Plot

pca.plot_loadings(n_pcs=2, thresh=0.7, save=True)

Scatter Plot

Here the tool will identify whether your target data is qualitative or quantitative and will apply appropriate customization.

pca.plot_scatter(plot_pcs=[1, 2], color_by_y=True, save=True)

Example Notebook

For a hands-on example, refer to the accompanying Jupyter notebook pca.ipynb.


License

This project is licensed under the Apache 2.0 License.


Contact

For questions or feedback, please reach out to the project maintainer.


About

Script to perform Principal Component Analysis

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages