A professional, full-stack web application built with Django and Machine Learning (Random Forest) to predict future product sales based on historical transaction datasets.
This application allows users to upload sales datasets (CSV/Excel format), processes the data dynamically, performs multi-product recursive forecasting, generates customized trend charts, and enables exporting the predicted sales tables back into CSV or Excel files.
- Interactive Web Interface: A modern, responsive frontend built with CSS3 animations, Bootstrap 5, and Django Crispy Forms.
- User Authentication: Secure signup, login, password reset, and session-based route protection using a custom decorator.
- Smart Dataset Processing: Seamless parsing of uploaded CSV and Excel (.xlsx) files.
- Profit & Loss Calculations: Automatic calculations of profit/loss fields on the uploaded dataset.
- Multi-Product Forecasting Engine: Uses a pre-trained Random Forest model for recursive forecasting (default horizon: 10 months) customized for multiple products.
- Dynamic Data Visualization: Generates high-quality Matplotlib line charts comparing historical data with forecasts, rendered directly in the UI as base64 images.
- Export Utilities: Quick export options to download predictions as CSV or formatted Excel files.
- Feedback System: Integrates a "Contact Us" form that saves user submissions to the database for administrative review.
- Backend: Django 5.x, Python 3
- Frontend: HTML5, CSS3, Bootstrap 5, FontAwesome, Django Crispy Forms (Bootstrap 5 pack)
- Machine Learning & Analytics: Scikit-learn (Random Forest Regressor), Pandas, NumPy, Joblib
- Data Visualization: Matplotlib
- Database: SQLite3 (Development)
├── config/ # Django project configurations (settings, urls, wsgi)
├── main/ # Core Django application containing views, models, forms, templates
│ ├── migrations/ # Database migrations
│ ├── static/ # CSS, JS, and image assets
│ ├── templates/ # HTML views (home, prediction, login, signup, base layout)
│ ├── models.py # CustomUser and ContactMessage models
│ ├── views.py # Core views, login/registration controllers, forecasting algorithms
│ └── forms.py # User registration and authentication forms
├── ml/ # Machine learning module
│ └── artifacts/ # Pre-trained Random Forest models and metadata (PKL, JSON)
├── requirements.txt # Python package dependencies
├── manage.py # Django management script
└── db.sqlite3 # Local SQLite database (ignored by git in production)
Follow these steps to run the project locally on your machine:
Make sure you have Python 3.10+ installed on your system.
git clone https://github.com/Awaisghan/Sales-Prediction-System.git
cd Sales-Prediction-SystemOn macOS/Linux:
python3 -m venv venv
source venv/bin/activateOn Windows:
python -m venv venv
venv\Scripts\activatepip install -r requirements.txtInitialize the database schemas:
python manage.py migrateTo access the Django admin panel, create an admin account:
python manage.py createsuperuserpython manage.py runserverOpen your browser and navigate to http://127.0.0.1:8000/.
The forecasting pipeline is executed in the following steps:
- Data Ingestion: The user uploads a CSV/Excel file containing transaction records (
date,product,sales,price,cost). - Feature Engineering: For each product group, historical lag features are generated:
sales_lag1,sales_lag2,sales_lag3(Previous 3 months of sales)sales_roll3(3-month rolling mean of sales)month(Extracted calendar month)
- Recursive Forecasting:
- A pre-trained
RandomForestRegressormodel (loaded frommodels_by_product.pkl) dynamically predicts the sales for the next month. - This predicted value is fed back recursively to build lag features for subsequent months, forecasting up to 10 months ahead.
- A pre-trained
- Data Visualization: Matplotlib plots a combined view of historical sales (green line) and forecasted sales (magenta line), showing clear trends and seasonal patterns.