The RFM Segmentation Tool is designed to help businesses analyze their sales transaction data and segment their customers based on Recency, Frequency, and Monetary (RFM) metrics. This tool utilizes multiple AI agents to manage the project, load and preprocess data, calculate RFM segments, and provide detailed insights and recommendations.
The project is organized into the following directories:
config/
: Contains YAML configuration files for agents and tasks.src/
: Contains the main scripts and agent scripts.agents/
: Contains the individual agent scripts.tools/
: Contains custom tools if necessary.
data/
: Contains the output files generated by the agents.venv/
: Virtual environment for the project.
- Project Manager: Manages the project scope and execution plan.
- Data Loader: Loads and preprocesses sales transaction data.
- RFM Calculator: Calculates RFM metrics and segments customers.
- Insight Provider: Analyzes RFM segments and provides detailed insights and recommendations.
- Python 3.11 (or a compatible version)
- Pip (Python package installer)
- Git (optional, for cloning the repository)
- Jupyter Notebook (optional, for running the notebook version)
- VS Code or PyCharm (optional, for running the script version)
- Ollama with
llama3:8B
model installed (or any local model of your preference)
-
Clone the Repository
git clone <https://github.com/cperazza/CrewAI_RFM_Segmentation> cd RFM_Tool
-
Create and Activate Virtual Environment
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Required Packages
pip install -r requirements.txt
-
Configure Local LLM via Ollama Set the following environment variables in your terminal or include them in a
.env
file.export OPENAI_API_BASE='http://localhost:11434/v1' export OPENAI_MODEL_NAME='openhermes' # Adjust based on available model export OPENAI_API_KEY=''
-
Run the Main Script
python src/main.py
- Goal: Define and manage the project scope and execution plan.
- Interaction:
- The agent will ask for detailed project guidelines. Provide a description of your project data.
- If you have reference files (CSV), provide the file path.
- The agent will analyze the data and provide an execution plan.
- Confirm if you are happy with the plan. If not, provide feedback, and the agent will adjust the plan accordingly.
- The agent will save the execution plan as a PDF in the
data/
folder.
- Goal: Load and preprocess sales transaction data.
- Interaction:
- The agent will ask for the path to the project data file (CSV).
- The agent will load and analyze the data, performing exploratory data analysis (EDA).
- Confirm if you have any questions about the data. The agent will use LLM to provide answers.
- The agent will calculate RFM, AOV, and AOI metrics and save the processed data as
processed_data.csv
in thedata/
folder. - Confirm if you are happy with the processed data. If not, provide feedback, and the agent will adjust the data accordingly.
- Goal: Calculate RFM metrics and segment customers.
- Interaction:
- The agent will ask for the path to the processed data file (processed_data.csv).
- The agent will calculate RFM segments using quartiles, quintiles, and deciles.
- The agent will save the segmented data as
rfm_segmented_data.csv
in thedata/
folder. - Confirm if you are happy with the segmented data. If not, provide feedback, and the agent will adjust the segmentation accordingly.
- Goal: Provide detailed insights and recommendations based on RFM analysis.
- Interaction:
- The agent will ask for the path to the segmented data file (rfm_segmented_data.csv).
- The agent will analyze the RFM segments and generate insights and visualizations.
- The agent will save the final report as a PDF and the chart code as a Python file in the
data/
folder. - Confirm if you are happy with the final report and insights. If not, provide feedback, and the agent will adjust the analysis accordingly.
To ensure the functionality and performance of the system, load real-life sales transaction data following the standard template:
customer_id
order_id
date
revenue
Follow the interaction guide to run the agents sequentially and verify the outputs at each stage.
This documentation provides a comprehensive guide to set up and run the RFM Segmentation Tool using AI agents. Follow the steps carefully to ensure a smooth setup and execution. If you encounter any issues, refer to the troubleshooting section or reach out for support.
- Virtual Environment Issues: Ensure the virtual environment is activated before running any scripts.
- Package Installation Errors: Check the
requirements.txt
file for any missing or conflicting packages. - LLM Configuration: Ensure the environment variables for Ollama are correctly set.
For further assistance, please contact [[email protected]].