Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BuyOrNot

Predicting Customer Purchase Behavior with Machine Learning Pipelines

BuyOrNot is a machine learning project that predicts whether a customer will make a purchase (it's generic, it could be a product, house, etc.) based on their demographics, using scikit-learn pipelines, preprocessing, and hyperparameter tuning. It is a binary classification problem, and basically the project gives an answer to this question: Based on age, income, gender, education level, marital status, children, job type, credit score, previous purchases and interest in newsletters, will this person make a purchase?

Where the output (purchased column) can be the following:

  • 1 = the person purchased (something)
  • 0 = the person did not purchase

It's designed for learning, experimentation, and potential real-world adaptation.

Results

The generated purchase data contains almost equal amounts of yes and no values. Generated Data

Final Model Accuracies:

  • RandomForest: Accuracy = 0.7650
  • GradientBoosting: Accuracy = 0.7550
  • LogisticRegression: Accuracy = 0.8050
  • SVC: Accuracy = 0.8150

Best Model: SVC with Accuracy = 0.8150

Confusion matrices Results

Top features Results

Features

  • Realistic dataset generation (age, income, gender)
  • Full data preprocessing (numeric + categorical) to filter missing values
  • Training multiple models (i.e. RandomForest, GradientBoosting, LogisticRegression and SVC) using pipelines
  • Tuning hyperparameters with GridSearchCV cross-validation
  • Evaluation with confusion matrix
  • Feature importance visualization
  • Saving and reloading the model
  • Making predictions on new data

Tech Stack

  • Python 3.10+
  • pandas, numpy, matplotlib
  • scikit-learn
  • joblib

Installation

git clone https://github.com/yourusername/BuyOrNot.git
cd BuyOrNot
pip install -r requirements.txt

Usage:

  1. Train the model
python src/train_model.py
  1. Make predictions
python src/predict.py

Example Prediction

new_person = pd.DataFrame({
    'age': [35],
    'income': [70000],
    'gender': ['Female'],
    'education_level': ['PhD'],
    'marital_status': ['Single'],
    'children': [1],
    'job_type': ['Professional'],
    'previous_purchase': [0],
    'credit_score': [850],
    'interested_in_newsletter': [False]
})

prediction = model.predict(new_person)

# Prediction Result
# ========================
# Will the person purchase? → Yes
# ========================

License

MIT License. Feel free to fork and adapt.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages