Automated RFM & KMeans Script
Performs RFM and Kmeans segmentation on your transaction data.
It has two modes,
- Automatic
- User-defined
When you run the app.py
script, it runs with automatic mode defaultly.
You don't need to do anything in automatic mode.
Cluster images and segmentation file are uploaded to outputs folder.
When you run the script with --manual
parameter, it runs in manual mode.
According to an elbow graph you need to specify the input for the number of clusters.
Sample usage:
python app.py --manual
GSheet Uploader Configuration
You can upload data to your google sheet in the script.
To do this, you need some steps.
First, you have to open and authorize a service account with your own Google account.
You can check this link for opening service account.
Then download your credentials script and save as **client-secret.json
** in root folder.
Folder Tree
├── app.py
├── client-secret.json
├── datasets
│ └── data.xlsx
├── outputs
├── requirements.txt
└── scripts
├── data_prep.py
└── loader.py
After these steps you have to share your Google Sheet with your service account as Editor.
Last Step:
Set your gsheet page in loader.py
Write your spreadsheet name and sheet name
spreadSheetName = 'Clustering Data' # GSheet Name
sheetName = 'Sayfa1' # Table name
If you have completed all these operations, you can run the script with the '--upload' parameter.
Sample Usage:
python app.py --upload
You can connect your Google sheet to data studio and create a customer segment dashboard.
bon appetit!
python app.py # Automatic mode
python app.py --upload # Automatic mode and gsheet upload
python app.py --manual # Manual mode
python app.py --upload --manual # Manual mode and gsheet upload
pandas~=1.4.3
matplotlib~=3.5.3
seaborn~=0.11.2
sklearn~=0.0
scikit-learn~=1.1.2
yellowbrick~=1.5
gspread~=5.4.0
oauth2client~=4.1.3
numpy~=1.23.2