A Flask-based product recommendation system that analyzes user purchase history from CSV files and recommends relevant products based on category preferences, brand affinity, discounts, popularity, and similarity scoring.
This project is designed to be simple, explainable, and demo-ready, suitable for:
- Mini-project / AI-ML integration demo
- Backend recommendation logic showcase
E-commerce platforms need to recommend products that match a user's interests while also considering brand loyalty, product popularity, and discounts.
In this project, we:
- Analyze past user orders stored in a CSV file
- Identify the user’s interest patterns (categories, brands, frequency, recency)
- Recommend new products from another CSV file
- Compute a hybrid similarity score (category + brand + popularity + discount)
- Display results in a web dashboard using Flask + Jinja2
All data is handled offline using CSV files (no database required).
User selects Customer ID
↓
System reads users_order.csv
↓
Finds dominant categories, brands & purchase behavior
↓
Matches with all_products.csv
↓
Computes hybrid similarity score
↓
Displays recommendations with explainability
project-root/
│
|__ product_images
├── app.py # Flask application
├── recommender.py # Recommendation logic (hybrid scoring)
│
├── data/
│ ├── users_order.csv # User purchase history
│ └── all_products.csv # Product catalog with brand, rating, reviews
│
├── templates/
│ ├── index.html # User selection page
│ ├── recommendations.html # Recommendation dashboard
│ ├── products.html # Full catalog view
│ └── users.html # All users & purchase histories
│
├── static/
│ └── images/ # Optional local images
│
└── README.md
Each row represents one product purchase by a user.
Columns:
customer_id– Unique user IDproduct_id– Product identifierproduct_name– Name of productproduct_category– Category (Electronics, Fashion, etc.)quantity– Quantity purchasedprice_usd– Price per unitpayment_method– Credit Card / Debit Card / Paypal / UPIorder_date– Purchase datetotal_amount– Final order value
✔ Users can purchase multiple categories and brands over time
Contains all available products on the platform.
Columns:
product_idproduct_nameproduct_categorypricediscount_pricestock_quantityimage_url(public real image URLs)brandrating(1–5 stars)reviews_count(number of reviews)
The system uses a hybrid content-based filtering approach:
- Count category-wise purchases
- Identify dominant brands & categories
- Consider quantity and recency
- Recommend products from:
- Frequently bought categories
- Same brands or related brands
- Exclude already purchased products
Each recommended product gets a score based on:
- Category match (cosine similarity)
- Brand affinity
- Popularity (rating + reviews)
- Discount attractiveness
- Recency bonus
Example:
Final Score = 0.5 * Category Similarity
+ 0.2 * Popularity
+ 0.2 * Discount
+ 0.1 * Diversity Factor
This score is shown in the UI for explainability.
1️⃣ User selects Customer ID from dropdown
2️⃣ System shows:
- Previously purchased products
- Recommended products
3️⃣ Recommendation cards include:
- Product image
- Name, category, brand
- Price (with discount)
- Rating & reviews
- Similarity score badge
- Python 3
- Flask – Backend web framework
- Pandas – Data processing
- Scikit-learn – Cosine similarity
- Jinja2 – HTML templating
- Bootstrap 5 – Frontend styling
- CSV Files – Data storage
pip install flask pandas scikit-learn
python app.pyThen open:
http://127.0.0.1:5000/✔ Demonstrates real-world recommendation logic
✔ Clear separation of data, logic, and UI
✔ Explainable AI (hybrid similarity scores)
✔ No heavy infrastructure required
✔ Easily extensible to ML models
- Collaborative filtering
- ML-based embeddings (Word2Vec, BERT)
- User clustering
- Database integration (MySQL / MongoDB)
- Login-based personalization
- Chart.js analytics (category distribution, score breakdown)
This project simulates a real e-commerce recommendation engine using hybrid scoring (category + brand + popularity + discount), making it ideal for learning, demos, and academic evaluation.