A machine learning web application that predicts the number of retail units sold based on various business and contextual factors such as inventory levels, discounts, promotions, and seasonal trends.
🚀 Live App: Click to Open on Hugging Face Spaces
This project presents an end-to-end regression pipeline designed to forecast retail sales performance.
The goal is to predict Units Sold using historical sales, demand forecasts, and other external features.
Two algorithms were tested — KNN Regressor and Linear Regression — and the final deployed model uses Linear Regression due to superior accuracy and generalization.
The application is built using Streamlit and organized into multiple interactive pages:
- Introduction
- Problem Statement & Objective
- Data Understanding
- Exploratory Data Analysis (EDA)
- Feature Engineering
- Model Overview
- Model Prediction
- The dataset was sourced from an open data repository.
- Contains both numerical and categorical features such as:
Category,Region,Inventory Level,Demand Forecast,Discount,Weather Condition,Holiday/Promotion, andSeasonality
- Target variable:
Units Sold
- Handled missing values and outliers
- Visualized feature distributions, boxplots, and correlations
- Identified major factors influencing sales performance:
- High demand during festive/holiday seasons
- Direct relationship between inventory level and units sold
- Discounts and promotions significantly increased sales
- Categorical Encoding: Ordinal Encoding applied to categorical variables
- Scaling Techniques: Used both
StandardScalerandMinMaxScalerdepending on the algorithm - Feature Selection:
Mutual Informationafter Standard ScalingSelectKBest (Chi²)after MinMax Scaling
- Outlier Handling: Applied capping on
Units SoldandDemand Forecast
- Non-parametric, distance-based algorithm
- Suitable for smaller datasets and nonlinear relationships
- Achieved R² Score: 0.964
- Slightly higher prediction errors due to sensitivity to scaling and feature dimensions
- Assumes a linear relationship between predictors and target
- More stable and interpretable
- Achieved R² Score: 0.993 ✅
- Selected as the final model for deployment due to:
- Higher accuracy
- Lower Mean Absolute Error (MAE) and RMSE
- Consistent performance across validation splits
| Metric | KNN Regressor | Linear Regressor |
|---|---|---|
| R² Score | 0.964 | 0.993 |
| Mean Absolute Error (MAE) | Higher | Lower |
| Root Mean Squared Error (RMSE) | Higher | Lower |
✅ Final Decision: Linear Regression selected as the deployed model.
- Python
- Streamlit (for web deployment)
- scikit-learn
- pandas, numpy, matplotlib, seaborn
git clone https://github.com/yourusername/Retail_Units_Sold_Prediction_App.git
cd Retail_Units_Sold_Prediction_App