A comprehensive, production-ready retail price optimization dashboard with machine learning models, price prediction, competitor analysis, and dynamic pricing strategies.
- Interactive Visualizations: Multiple chart types including histograms, box plots, scatter plots, correlation heatmaps
- Real-time Price Prediction Calculator: Input product parameters for instant predictions
- Advanced Analytics Dashboard: KPI metrics, market analysis, and data exploration tools
- Export & Reporting: Download filtered data in CSV, Excel, or JSON format
- Decision Tree Regressor
- Random Forest Regressor
- Gradient Boosting Regressor
- Linear/Ridge/Lasso Regression
- Model evaluation with multiple metrics (RΒ², RMSE, MAE, MAPE)
- Cross-validation support
- Feature importance analysis
- Multiple Pricing Strategies:
- Cost-plus pricing
- Competitor-based pricing
- Value-based pricing
- Dynamic pricing
- Penetration pricing
- Price skimming
- Price elasticity analysis
- Competitive position analysis
- Profit margin optimization
- Statistical analysis (descriptive stats, correlations, hypothesis testing)
- Trend analysis and forecasting
- Category performance metrics
- Customer behavior analysis
- Product segmentation
- RESTful API with FastAPI
- Price prediction endpoint
- Optimization endpoints
- Batch processing support
- Health monitoring
Retail-Prices/
βββ app.py # Main Streamlit application
βββ Optimized.py # Enhanced Streamlit dashboard
βββ config.py # Configuration settings
βββ data_validation.py # Data validation utilities
βββ retail_price.csv # Dataset
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
β
βββ models/ # Machine Learning Models
β βββ __init__.py
β βββ price_predictor.py # Price prediction models
β βββ model_evaluator.py # Model evaluation tools
β βββ feature_importance.py # Feature importance analysis
β
βββ utils/ # Utility Modules
β βββ __init__.py
β βββ price_optimizer.py # Price optimization engine
β βββ data_preprocessing.py # Data preprocessing utilities
β βββ analytics.py # Analytics engine
β βββ visualizations.py # Chart building utilities
β βββ logger.py # Logging configuration
β βββ database.py # Database connector
β βββ report_generator.py # Report generation
β
βββ api/ # API Module
β βββ main.py # FastAPI endpoints
β
βββ pages/ # Streamlit Pages
β βββ 1_π¦_Inventory_Analysis.py
β βββ 2_π_Sales_Forecast.py
β βββ 3_πͺ_Competitor_Analysis.py
β
βββ tests/ # Test Suite
β βββ conftest.py # Pytest configuration
β βββ test_modules.py # Unit tests
β
βββ .github/ # GitHub Actions
βββ workflows/
βββ ci.yml # CI/CD pipeline
- Python 3.9 or higher
- pip package manager
- Clone the repository
git clone https://github.com/kamrankamrankhan/Retail-Prices.git
cd Retail-Prices- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Run the Streamlit app
streamlit run app.py- Run the FastAPI server (optional)
uvicorn api.main:app --reload --port 8000# Build and run with Docker Compose
docker-compose up -d
# Access the dashboard
# Streamlit: http://localhost:8501
# API: http://localhost:8000from models.price_predictor import PricePredictor
import pandas as pd
# Load data
data = pd.read_csv('retail_price.csv')
data['comp_price_diff'] = data['unit_price'] - data['comp_1']
# Initialize and train model
predictor = PricePredictor(model_type='random_forest')
predictor.fit(data)
# Make prediction
predicted_price = predictor.predict_single(
qty=100,
unit_price=50.0,
comp_price=45.0,
product_score=4.5
)
print(f"Predicted Price: ${predicted_price:.2f}")from utils.price_optimizer import PriceOptimizer, PricingStrategy
import pandas as pd
data = pd.read_csv('retail_price.csv')
optimizer = PriceOptimizer(data)
# Optimize price using competitor-based strategy
result = optimizer.optimize_price(
product_id='bed1',
strategy=PricingStrategy.COMPETITOR_BASED,
position='competitive'
)
print(f"Optimal Price: ${result.optimal_price}")
print(f"Expected Revenue: ${result.expected_revenue}")from utils.data_preprocessing import DataPreprocessor
preprocessor = DataPreprocessor(data)
preprocessor.remove_duplicates()\
.handle_missing_values(strategy='mean')\
.remove_outliers(method='iqr')\
.create_features()
processed_data = preprocessor.get_processed_data()| Endpoint | Method | Description |
|---|---|---|
/ |
GET | API info |
/health |
GET | Health check |
/predict |
POST | Price prediction |
/optimize |
POST | Price optimization |
/optimize/batch |
POST | Batch optimization |
/products |
GET | List products |
/categories |
GET | List categories |
/analytics/summary |
GET | Analytics summary |
# Predict price
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{
"qty": 100,
"unit_price": 50.0,
"comp_1": 45.0,
"product_score": 4.5
}'# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov=. --cov-report=html
# Run specific test file
python tests/test_modules.py- Main Dashboard (
app.py) - Core analytics and visualizations - Inventory Analysis - Stock levels and product performance
- Sales Forecast - Predictive sales analytics
- Competitor Analysis - Market position comparison
Edit config.py to customize:
# Application settings
APP_TITLE = "Retail Price Analytics Dashboard"
DATA_FILE = "retail_price.csv"
# Model settings
DEFAULT_TEST_SIZE = 20
DEFAULT_RANDOM_STATE = 42
# Data validation thresholds
MAX_PRICE_THRESHOLD = 10000
MIN_QUALITY_SCORE = 70- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Streamlit for the amazing dashboard framework
- Scikit-learn for machine learning utilities
- Plotly for interactive visualizations
- FastAPI for the high-performance API framework
For issues and feature requests, please use the GitHub Issues page.
Built with β€οΈ for Retail Analytics