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.
- 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.
- Clone or download the repository.
- Ensure the required Python packages are installed:
pip install pandas scikit-learn matplotlib numpy
from PCA_tool import PCA_toolimport 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)pca.perform_pca(scale=True) # Set `scale=False` to skip autoscalingpca.save_data(filename='pca_results')pca.plot_scree(num_pcs=10, save=True)pca.plot_loadings(n_pcs=2, thresh=0.7, save=True)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)For a hands-on example, refer to the accompanying Jupyter notebook pca.ipynb.
This project is licensed under the Apache 2.0 License.
For questions or feedback, please reach out to the project maintainer.