Times Series Forecasting and Customer Segmentation using Sales data from a beauty shop in Lusaka, Zambia.
# Introduction
The project demonstrates basic time-series predictions and implementation of a dashboard using Tableau. The project was part of the The Africa Data Science Intensive (DSI) program. Softare used for this project:
* MySQL
* Python
* Tableau
# Files in Project
| File | Description |
|---|---|
| salon_analytics_predictions.ipynb | Contains the time-series predictions using Prophet, xGBoost and LSTM|
| customer_segmentation.ipynb | Contains customer segmentation using RFM (Recency, Frequency and Monetary) |
| write_main_table.py|Updates the main sql table "salon_analytics" to local database |
| write_forecast.py|Updates the main sql table "forecasts" to local database |
| write_segments.py | Updates the main sql table "segments" to local database |
# Dataset
The project uses an anonymized dataset from a beauty shop in Lusaka, Zambia. The sale amounts (total) are also scaled to keep the business information private. dataset columns:
* **Date**: Hourly timestamp of customer purchases
* **Customer**: Customer ID
* **Total**: Amount purchased.
The plot below shows the full plot of the dataset, it contains a timestamp of when each transaction was made.
# Loading dataset into MySQL Database
The data is loaded into a local MySQL database using python, after which Tableau is used to connect to the data for the dashboard. sqlalchemy makes it easy to load data straight to MySQL databases. The following code shows an example of loading the main table to the database:
```Bash
import pandas as pd
import sqlalchemy
from sqlalchemy import create_engine
#database credentials and details
user = 'root'
passw = '******' #insert your password here
host = 'localhost'
port = 3306
database = 'salon_analytics'
#read original customer data
customer_data = pd.read_csv("data.csv", decimal=".")
customer_data['Date']=pd.to_datetime(customer_data['Date'].astype(str))
database_connection = create_engine('mysql+mysqlconnector://{0}:{1}@{2}/{3}'.
format(user, passw,
host, …