This project builds and deploys an Artificial Neural Network (ANN) to predict whether a customer is likely to make a purchase, based on demographic and behavioral features.
The solution includes data preprocessing, model training, evaluation, and deployment with a simple app interface.
.
├── customerData.csv # Original dataset (50,000 rows)
├── ann_customer_purchase_prediction.ipynb # Main notebook (preprocessing + model training)
├── app.py # Streamlit app for deployment
├── train.ipynb # Training script (alternative to main notebook)
├── accuracy_loss.png # Training accuracy/loss curves
├── models/ # (Optional) Saved models and encoders
│ ├── purchasePredictionModel.h5
│ ├── scaler.pkl
│ ├── label_encoder_gender.pkl
│ └── onehot_encoders_*.pkl
-
Clone this repository:
git clone https://github.com/your-username/customer-purchase-prediction.git cd customer-purchase-prediction -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # Mac/Linux venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
- The dataset contains 50,000 entries of customer records.
- Features include demographics (Age, Gender, Region), behavior (Purchases, Time spent, Discounts availed), and loyalty information.
- Target: PurchaseStatus (0/1).
Synthetic expansion to 500k rows can also be generated for large-scale testing.
- Input: Encoded + scaled feature set
- Hidden Layers:
- Dense(128, ReLU, with L2/Dropout)
- Dense(64, ReLU)
- Output: Dense(1, Sigmoid)
- Loss:
binary_crossentropy - Optimizer:
Adam - Callbacks: EarlyStopping (patience=10, restore best weights), TensorBoard
Run the notebook or the training script:
jupyter notebook ann_customer_purchase_prediction.ipynbor
python train.ipynbThe model and preprocessing objects are saved as:
purchasePredictionModel.h5scaler.pkllabel_encoder_gender.pklonehot_encoders_*.pkl
Run the app locally:
streamlit run app.pyThis opens a web UI where you can enter customer details and get a prediction.
- Validation Accuracy: ~92.5%
- Validation AUC: ~0.93
- Stable training with minimal overfitting
- Example accuracy/loss curve:
- Predict customer purchase likelihood
- Support loyalty program targeting
- Guide marketing campaign personalization
- Forecast sales in e-commerce/retail
- Python 3.9+
- TensorFlow 2.x
- scikit-learn
- pandas, numpy, matplotlib
- streamlit (for app)
Install with:
pip install tensorflow scikit-learn pandas numpy matplotlib streamlitDeveloped by Gautham Vijayaraj.
Feel free to fork, improve, and use for your own ML projects!
