A Python library for automated feature engineering tailored to clustering in customer personality analysis within the retail industry.
Project description
customer_personality_analysis_afe
Automated Feature Engineering Framework for Customer Personality Analysis in the Retail Industry
Overview
This repository provides a one-stop solution for data cleaning, GPT-powered transformations, feature engineering, and feature reduction—all tuned specifically for Clustering tasks, useful for Customer Personality Analysis in a retail setting.
With a single orchestrator pipeline, users can:
- Drop or impute problematic columns,
- Automatically generate Python code via GPT to transform their DataFrame,
- Engineer advanced features (e.g., frequency encoding, pairwise interactions, scaling),
- Perform Ant Colony Optimization (ACO) for feature reduction.
Key Features
-
Data Cleaning
- Drop single-value columns
- Impute missing values (median/mode)
- Convert binary columns to boolean
- Winsorize outliers at 1st/99th percentile
-
GPT Transformations
- Summarize DataFrame schema and produce a “checklist”
- Generate dynamic Python code in
<start_code> ... <end_code>blocks - Execute GPT-generated transformations automatically on your DataFrame
-
Feature Engineering
- Frequency encode categorical columns
- Transform boolean columns to numeric “weights”
- Create pairwise interactions (squared, sqrt, products, divisions)
- Standard scaling for numerical features
-
Feature Reduction
- Ant Colony Optimization to pick an optimal subset of features
- Evaluate subset quality using Calinski-Harabasz (CHI) and Davies-Bouldin (DBI)
-
Orchestrator Pipeline
- A single class (
AutomatedPipeline) that ties all steps into a.run_pipeline()call - Configurable toggles to skip or include GPT transformations, advanced feature ops, or ACO-based reduction
- A single class (
-
Automated Clustering and Visualization
- Perform Principal Component Analysis (PCA) with IQR filtering to select the top 3 valid components.
- Use KMeans clustering to group customers into distinct segments.
- Visualize clusters in 3D using interactive plotly
Installation
- Clone or Download this repo:
git clone https://github.com/ethandt210/customer_personality_analysis_afe.git cd customer_personality_analysis_afe
- Install via
pip:pip install -e .
Usage Example
Automated Feature Engineering Pipeline
import pandas as pd
from clustering_afe import automated_feature_engineering
# Suppose you have a CSV file
df_raw = pd.read_csv("customer_marketing_data.csv")
# Provide your OpenAI API key to enable GPT transformations
my_api_key = "sk-YourOpenAIKeyHere"
# Create the pipeline
afe = automated_feature_engineering(df_raw, my_api_key)
# Run the entire pipeline:
# 1) Data Cleaning
# 2) GPT transformations
# 3) Feature transformations
# 4) Feature reduction (ACO)
df_final = afe.run_pipeline(
use_gpt=True,
do_feature_engineering=True,
do_aco=True
)
print("Final DataFrame Shape:", df_final.shape)
print("Selected Features:", pipeline.meta_info.get("best_features"))
Automated Clustering and Visualization
import pandas as pd
from clustering_afe import automated_clustering
# Initialize the clustering pipeline
clustering = automated_clustering(df_final)
# Normalize components via PCA (up to 10 components, retain top 3 valid ones)
df_pca = clustering.run_component_normalization(n_components=10)
# Cluster the data using KMeans
df_pca, (chi, dbi) = clustering.cluster_pca_kmeans(n_clusters=afe.meta_info['best_k'], random_state=42)
print(f"Calinski-Harabasz Score: {chi}")
print(f"Davies-Bouldin Score: {dbi}")
# Visualize the clusters in 3D
clustering.visualize_clusters(cluster_col="cluster", chart_title="Customer Segmentation")
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
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 clustering_afe-1.1.9.tar.gz.
File metadata
- Download URL: clustering_afe-1.1.9.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
939b9a950a072b79a4fa899094a4b9d06def90440cdeddcc6c42e9bec123de3a
|
|
| MD5 |
e426b89090df98ad8baed054657c6933
|
|
| BLAKE2b-256 |
e411c3596b9a6b5fb46dcf966196eb232deb02a9d886e4b7a5d99cd69f0b05d3
|
File details
Details for the file clustering_afe-1.1.9-py3-none-any.whl.
File metadata
- Download URL: clustering_afe-1.1.9-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4abe7a34c2a30ea6c2963ba87552090bda3b4e874e43dda4071df8b4bce27ec
|
|
| MD5 |
4f3c233c1a6234ae679f006a588d6709
|
|
| BLAKE2b-256 |
9354c3b070e5e7d90f191cdecc47e9e9a50d6b55910d94e272fc68585f5c2ac0
|