Skip to content

Smartphone Purchase Prediction Dashboard - An interactive web application for predicting and analyzing smartphone purchase behavior.

License

Notifications You must be signed in to change notification settings

Mandar123454/Predictive-Modeling-for-Smartphone-Purchase-Behavior-ML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

61 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

SmartPredict Logo

๐Ÿ“ฑ SmartPredict

Predictive Modeling for Smartphone Purchase Behavior

An interactive machine learning dashboard that predicts smartphone purchasing behavior
based on demographic factors, user preferences, and market trends.

Live Demo


Python Flask scikit-learn pandas NumPy Chart.js

Azure License Last Commit Issues PRs Welcome

Accuracy ROC-AUC Response Time Records


โœจ Highlights

๐ŸŽฏ What It Does

  • Predicts smartphone purchase probability using ML
  • Analyzes demographic patterns & market trends
  • Compares brands with comprehensive metrics
  • Visualizes data with interactive Chart.js charts

๐Ÿš€ Why It's Great

  • 87%+ accuracy Random Forest model
  • Real-time predictions with instant feedback
  • Beautiful UI with dark mode & animations
  • Production-ready deployed on Azure

๐ŸŽฏ Features

๐Ÿ“Š Dashboard Sections

Section Description
Overview Project metrics, model performance summary, and quick stats
Demographics Interactive demographic analysis with purchase patterns by age, gender, income
Prediction Tool Real-time ML predictions with user demographic input
Brand Comparison Comprehensive brand analysis, market share, and loyalty metrics
Insights Advanced analytics, user segments, and business intelligence
Documents Access reports, notebooks, and project documentation

โšก Key Capabilities

  • โœ… 87%+ Prediction Accuracy with optimized Random Forest
  • โœ… Interactive Visualizations using Chart.js
  • โœ… Real-time Predictions with instant probability scores
  • โœ… Brand Intelligence with market share analysis
  • โœ… Export Functionality for charts and data
  • โœ… Mobile Responsive design for all devices
  • โœ… Dark Mode with smooth animations
  • โœ… PWA Support with offline capabilities

๐Ÿ› ๏ธ Tech Stack

Python
Python
Flask
Flask
scikit-learn
Scikit-learn
HTML
HTML5
CSS
CSS3
JavaScript
JavaScript
Azure
Azure
Layer Technologies
Backend Python 3.11, Flask 2.2.5, Flask-CORS, Gunicorn
ML/Data Scikit-learn 1.7.1, Pandas 2.3.2, NumPy 2.3.3, Joblib
Frontend HTML5, CSS3, JavaScript ES6+, Bootstrap 5
Visualization Chart.js 4.x, Custom animations
Deployment Azure App Service, Gunicorn WSGI

๐Ÿš€ Quick Start

Option 1: Visit Live Demo

๐Ÿ‘‰ https://smartpredict-app-a3gcecfectcudbdd.centralindia-01.azurewebsites.net

Option 2: Run Locally

# Clone the repository
git clone https://github.com/Mandar123454/Predictive-Modeling-for-Smartphone-Purchase-Behavior-ML.git
cd Predictive-Modeling-for-Smartphone-Purchase-Behavior-ML

# Create virtual environment
python -m venv .venv

# Activate virtual environment
# Windows:
.venv\Scripts\activate
# Linux/Mac:
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Run the dashboard
python run_dashboard.py

Then open http://localhost:5000 in your browser.

Option 3: Windows Quick Setup

# Just run the setup script
.\setup.bat

๐Ÿ“ Project Structure

๐Ÿ“ฆ SmartPredict
โ”œโ”€โ”€ ๐Ÿ“„ app.py                    # Root entry point
โ”œโ”€โ”€ ๐Ÿ“„ run_dashboard.py          # Cross-platform launcher
โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt          # Python dependencies
โ”œโ”€โ”€ ๐Ÿ“„ Procfile                  # Azure/Heroku deployment
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Dashboard/                # Web application
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ app.py               # Flask backend & API
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ index.html           # Main dashboard UI
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ css/                 # Stylesheets (dark mode, animations)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ js/                  # JavaScript modules & charts
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚ data/                # Static visualization data
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Data/                     # ML datasets
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ smartphone_purchased_data.csv
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ smartphone_purchased_data_cleaned.csv
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ smartphone_purchased_data_updated.csv
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Models/                   # Trained ML models
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ model.pkl            # Random Forest model
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ scaler.pkl           # Feature scaler
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ model_columns.pkl    # Column mappings
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Notebook/                 # Jupyter notebooks
โ”‚   โ”œโ”€โ”€ ๐Ÿ““ Main Notebook.ipynb
โ”‚   โ”œโ”€โ”€ ๐Ÿ““ exploratory_analysis.ipynb
โ”‚   โ””โ”€โ”€ ๐Ÿ““ feature_influence_analysis.ipynb
โ”‚
โ””โ”€โ”€ ๐Ÿ“‚ Project Report/           # Documentation
    โ”œโ”€โ”€ ๐Ÿ“„ DOCS.md
    โ””โ”€โ”€ ๐Ÿ“„ PROJECT_OVERVIEW_ALL_IN_ONE.md

๐Ÿš€ Deploy to Azure

This project is Azure App Service ready with included Procfile and Gunicorn configuration.

# Quick deploy with Azure CLI
az webapp up --name your-app-name --resource-group your-rg --runtime "PYTHON:3.11"

๐Ÿ“– See AZURE_DEPLOY.md for detailed deployment guide.


๐Ÿ“Š Model Performance

๐Ÿ“ˆ Metrics

Metric Score
Accuracy 87.3%
Precision 85.1%
Recall 89.7%
F1-Score 87.3%
ROC-AUC 0.924

๐Ÿ”ฌ ML Pipeline

  1. Data Preprocessing - Missing values, outliers
  2. Feature Engineering - 18 derived features
  3. Model Training - Random Forest + tuning
  4. Cross-Validation - 10-fold CV
  5. Evaluation - Multiple metrics

๐Ÿ”Œ API Reference

Endpoint Method Description
/api/status GET Health check & API status
/api/data GET Dataset statistics
/api/feature_importance GET Model feature importance
/api/predict POST Purchase prediction
/api/compare_brands POST Brand comparison
/api/segment_analysis GET User segment analysis

Example Usage

import requests

response = requests.post('http://localhost:5000/api/predict', json={
    'age': 28,
    'gender': 'Male',
    'income': 65000,
    'education': "Bachelor's"
})

print(f"Purchase Probability: {response.json()['probability']}%")

๐Ÿ” Troubleshooting Guide

Common Issues and Solutions

Issue: "Python not found"

# Solution: Install Python from python.org
# Verify installation:
python --version
# or
python3 --version

Issue: "Module not found" errors

# Solution: Install missing dependencies
pip install flask flask-cors pandas numpy scikit-learn

# Or reinstall all requirements
pip install -r requirements.txt

Issue: "Port 5000 already in use"

# Solution 1: Kill the process using port 5000
# Windows:
netstat -ano | findstr :5000
taskkill /PID <PID_NUMBER> /F

# Linux/Mac:
lsof -ti:5000 | xargs kill -9

# Solution 2: Use a different port
# Edit Dashboard/app.py and change:
# app.run(host='0.0.0.0', port=5001, debug=True)

Issue: "Model files not found"

# The dashboard will run in demo mode
# This is normal and provides sample predictions
# Real models will be loaded if present in Models/ folder

Issue: Dashboard loads but charts don't appear

# Solution: Clear browser cache and refresh
# Or try in an incognito/private browsing window

๐ŸŽฏ What Users Can Do

๐Ÿ“Š Explore Demographics

  • Age Analysis: View purchase patterns across age groups
  • Income Impact: See how income affects buying decisions
  • Gender Insights: Compare male vs female purchasing behavior
  • Education Correlation: Analyze education level impacts

๐Ÿ”ฎ Make Predictions

  • Input Demographics: Age, gender, income, education
  • Set Preferences: Brand, price range, feature priorities
  • Get Predictions: Real-time purchase probability (0-100%)
  • Understand Why: See which factors influence the prediction

๐Ÿ† Compare Brands

  • Market Share: View brand popularity over time
  • Loyalty Analysis: See which brands retain customers best
  • Feature Comparison: Compare what each brand offers
  • Demographic Preferences: See which age groups prefer which brands

๐Ÿ’ก Gain Insights

  • User Segments: Discover different customer types
  • Price Sensitivity: Understand how price affects purchases
  • Seasonal Trends: See when people buy phones most
  • Feature Importance: Learn which features matter most

๐Ÿ“ˆ Performance Notes

  • Prediction Speed: < 100ms average response time
  • Model Accuracy: 87.3% on test data
  • Data Size: 10,000+ smartphone purchase records
  • Features: 18 engineered features for prediction
  • Browser Compatibility: All modern browsers supported
  • Mobile Responsive: Works on phones and tablets

๐Ÿš€ API Endpoints (For Developers)

When running locally, the following REST API endpoints are available:

  • GET /api/status - Check API health and status
  • GET /api/data - Basic dataset statistics and distributions
  • GET /api/feature_importance - Model feature importance (or fallback)
  • POST /api/predict - Purchase prediction for user input
  • POST /api/compare_brands - Compare probabilities across brands
  • GET /api/segment_analysis - Segment analysis by age, income, brand

Example API Usage:

import requests

# Get a prediction
response = requests.post('http://localhost:5000/api/predict', json={
    'age': 28,
    'gender': 'Male', 
    'income': 65000,
    'education': "Bachelor's"
})
prediction = response.json()
print(f"Purchase Probability: {prediction['probability']}%")

๐Ÿ“š Data Science Details

Dataset Information

  • Source: Synthetic smartphone purchase behavior data
  • Size: 10,841 records with 18 features
  • Target: Binary classification (Will Purchase: Yes/No)
  • Features: Demographics, financial, behavioral, and preference data

Machine Learning Pipeline

  1. Data Preprocessing: Missing value imputation, outlier detection
  2. Feature Engineering: Create derived features, categorical encoding
  3. Model Training: Random Forest with hyperparameter tuning
  4. Validation: 10-fold cross-validation, train-test split
  5. Evaluation: Accuracy, Precision, Recall, F1-Score, ROC-AUC

Model Performance Metrics

  • Overall Accuracy: 87.3%
  • Precision: 85.1% (true positive rate)
  • Recall: 89.7% (sensitivity)
  • F1-Score: 87.3% (harmonic mean of precision/recall)
  • ROC-AUC: 0.924 (excellent discrimination)

๐Ÿ“„ Reports & Documents

  • One-File Overview: Project Report/PROJECT_OVERVIEW_ALL_IN_ONE.md
  • Technical Documentation: Project Report/DOCS.md
  • Full ML Report (PDF): Project Report/ML Report MK.pdf

๐ŸŽ“ Educational Use

This project is perfect for:

  • Machine Learning Students: Learn end-to-end ML project development
  • Data Science Courses: Understand feature engineering and model evaluation
  • Business Analytics: See how ML applies to real-world business problems
  • Web Development: Learn Flask backend with interactive frontend integration

๐Ÿค For Contributors

Development Setup

# Fork the repository on GitHub
git clone https://github.com/YOUR-USERNAME/Predictive-Modeling-for-Smartphone-Purchase-Behavior-ML.git
cd Predictive-Modeling-for-Smartphone-Purchase-Behavior-ML

# Create virtual environment (recommended)
python -m venv smartpredict_env
source smartpredict_env/bin/activate  # Linux/Mac
# or
smartpredict_env\Scripts\activate     # Windows

# Install development dependencies
pip install -r requirements.txt
pip install pytest flask-testing jupyter

# Run tests
python -m pytest

# Start development server
python run_dashboard.py

Contributing Guidelines

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Areas for Contribution

  • Model Enhancement: Improve prediction accuracy
  • New Visualizations: Add more interactive charts
  • UI/UX Improvements: Enhance user interface
  • Performance Optimization: Speed up loading times
  • Mobile Experience: Improve responsive design
  • Documentation: Expand guides and tutorials

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Attribution & Responsible Use

If you reuse or modify this project (commercially or nonโ€‘commercially) you must:

  1. Retain the original copyright notice: Copyright (c) 2025 Mandar123454
  2. Keep the MIT license text in your distribution (LICENSE file)
  3. Clearly document any major modifications you make

Recommended (not legally required under MIT):

  • Link back to this repository so others can find the source
  • Add a short note like: โ€œBased on SmartPredict โ€“ Smartphone Purchase Prediction Dashboard (MIT Licensed)โ€

No warranties are provided; see โ€œAS ISโ€ clause in the license. Use at your own risk.

Contribution Licensing

By submitting a Pull Request you agree your contribution is provided under the same MIT License and that you have the right to license it. If you include thirdโ€‘party code, ensure its license is compatible and note it in a new THIRD_PARTY_NOTICES section or file.

Additional Legal Artifacts

The repository may include (or you can add):

  • NOTICE โ€“ Highโ€‘level copyright + license pointer (for downstream bundlers)
  • CONTRIBUTING.md โ€“ How to propose changes, coding standards, and review process

If these files appear later, they will complement (not replace) the MIT terms.

๐Ÿ™ Acknowledgments

scikit-learn Flask Chart.js Bootstrap


๐Ÿ“ž Support

Need help? Here's how to get support:

  1. Check the Troubleshooting Section above
  2. Review Documentation: See Project Report/DOCS.md
  3. GitHub Issues: Open an issue for bugs or feature requests
  4. Discussions: Use GitHub Discussions for questions

Made with โค๏ธ by the SmartPredict Team
Helping businesses make data-driven decisions about smartphone market trends.

Star