Pricing is the toughest decision for any business.
Imagine a shop selling noodles. A few years ago when there was no competition, they could charge ₹5. Then as the market grew, they increased price to ₹10. Customers accepted it because:
- The brand was trusted
- Quality was good
- No better alternatives existed
Then competition arrived.
Other brands offered similar noodles at lower prices. The shop thought: "We're the market leader, let's charge ₹12 instead."
What happened? Customers switched to competitors offering the same product at ₹10. Sales crashed. Profit collapsed.
Why? Because when competition exists, you can't just increase price. Customers will leave.
This happens to EVERY business:
✗ Too high price → Customers switch to competitors → Low volume → Low profit
✗ Too low price → Volume is good but margins crushed → Low profit
✓ Perfect price → Good volume + Good margins = Maximum profit
But how do you find that perfect price?
Most businesses guess. They try ₹10, see what sells. Then try ₹12, see sales drop. Then go back to ₹10. This is chaos!
What if you could predict the best price using DATA?
This system uses Machine Learning (XGBoost) to analyze your past sales data and tell you:
- "Your optimal price is ₹10.50, not ₹12"
- "This product can handle a price increase"
- "This product should keep its current price"
- "If competitor goes down to ₹8, you should reconsider"
BEFORE (Guessing):
Month 1: ₹10 price, ₹3,000 profit
Month 2: Increase to ₹12, ₹1,000 profit (oops!)
Month 3: Back to ₹10, ₹3,000 profit
Average: ₹2,333/month (wasted potential)
AFTER (Smart Pricing):
Month 1: ₹10 price, ₹3,000 profit
Month 2: Tested ₹10.50, ₹3,200 profit ✅
Month 3: Stayed at ₹10.50, ₹3,200 profit ✅
Average: ₹3,133/month (30% GAIN!)
Collect your past sales records:
- What price you charged
- How many units sold at that price
- Your cost per unit
- Date/time period
The XGBoost model analyzes:
- "When price went from ₹10 to ₹12, sales dropped 80%"
- "When price stayed at ₹10, sales stayed consistent"
- "Customers are price-sensitive to changes above ₹11"
Model tells you:
- Current price: ₹10, Sales: 100/day, Profit: ₹200/day
- If you try ₹10.50: Predicted sales: 95/day, Profit: ₹220/day ✅
- If you try ₹11: Predicted sales: 40/day, Profit: ₹80/day ❌
- If you try ₹12: Predicted sales: 10/day, Profit: ₹30/day ❌
Recommendation: Stay at ₹10 or try ₹10.50 MAX
No more guessing!
- Implement the recommended price
- Monitor sales
- Adjust based on real market conditions
Place retail_price.csv in the project folder with these columns:
| Column | Description |
|---|---|
unit_price |
Price you're currently charging (₹) |
units_sold |
Number of units sold at that price |
cost_price |
Cost to produce/buy the unit |
product_category_name |
Category (Noodles, Snacks, etc.) |
product_id |
Unique product identifier |
month_year |
Month of sale (for trends) |
pip install pandas numpy matplotlib seaborn xgboost joblib streamlit scikit-learnOr use:
pip install -r requirements.txt| Aspect | Details |
|---|---|
| Algorithm | XGBoost Regressor |
| Purpose | Predict optimal pricing |
| Training Data | 80% of historical sales |
| Testing Data | 20% for validation |
| Metrics | RMSE (accuracy) & R² (model quality) |
| Parameters | max_depth=5, learning_rate=0.1, n_estimators=150 |
When you run the app, you get:
- 📊 Data Preview - See your sales history at a glance
- 📈 Model Performance - How accurate are the predictions?
- 🔍 Feature Importance - What factors matter most for pricing?
- 💡 Top Opportunities - Which products are underpriced/overpriced?
- 🧾 Custom Prediction - "What if I price this at ₹12?" Get instant predictions
- 📉 Price vs Sales Relationship - Visualize how price affects demand
streamlit run smart_price_optimization.pyThen:
- Upload your sales data (or use the included retail_price.csv)
- View the dashboard
- Check predictions for different price points
- Get recommendations
- Implement the optimal price
✅ Retail shops - Price products to beat competition while keeping profit
✅ Food vendors - Find the price customers will happily pay
✅ E-commerce stores - Dynamic pricing based on market data
✅ Restaurants - Menu item pricing strategy
✅ FMCG brands - Wholesale pricing optimization
PROFIT = (Price - Cost) × Quantity Sold
NOT: "Higher price = more profit"
BUT: "Price that keeps volume high = more profit"
EXAMPLE:
₹12 price: (12-6) × 10 units = ₹60 profit
₹10 price: (10-6) × 50 units = ₹200 profit ✅