A web-based application for sales forecasting and analysis using machine learning. Built with Streamlit and Facebook's Prophet forecasting model, this tool helps businesses predict future sales trends based on historical data.
- Data Upload: Upload CSV files with historical sales data
- Sales Forecasting: Generate predictions using Facebook's Prophet model
- Advanced Analysis: Deep dive into sales patterns and seasonality
- Interactive Visualizations: Charts and graphs using Plotly
- Export Results: Download forecasts and analysis as CSV or PDF
- Trend Analysis: Identify long-term growth patterns
- Seasonality Detection: Uncover weekly, monthly, and yearly patterns
- Anomaly Detection: Find unusual sales patterns
- What-if Scenarios: Test different forecasting parameters
- Performance Metrics: MAE, RMSE, MAPE, and MSE calculations
- Forecast Plots: Interactive charts with confidence intervals
- Component Analysis: Break down trend, seasonality, and holiday effects
- Residual Analysis: Model performance visualization
- Monthly Breakdowns: Detailed period analysis
- Seasonal Decomposition: Advanced time series analysis
- Python 3.7 or higher
- pip (Python package installer)
-
Clone or download the project
cd SalesForecastAI
-
Install required dependencies
pip install -r requirements.txt
-
Run the application
streamlit run app.py
-
Access the app
- The application will automatically open in your default web browser
- Default URL:
http://localhost:8501
Your CSV file must contain at least two columns:
Column | Format | Example |
---|---|---|
Date | YYYY-MM-DD | 2023-01-01 |
Sales | Numeric | 1000.50 |
You can include additional numeric columns that might influence sales:
- Marketing spend
- Price changes
- Promotional events
- External factors
- Minimum Data: At least 1 year of historical data for better seasonality detection
- Consistent Format: Ensure dates are in YYYY-MM-DD format
- Clean Data: Remove or explain outliers
- Regular Intervals: Daily data works best, but weekly/monthly is also supported
The application uses Facebook's Prophet model with configurable parameters:
Parameter | Description | Default | Impact |
---|---|---|---|
changepoint_prior_scale |
Trend flexibility | 0.05 | Higher = more flexible trend |
seasonality_prior_scale |
Seasonality strength | 10.0 | Higher = stronger seasonality |
confidence_interval |
Prediction uncertainty | 0.95 | 95% confidence interval |
forecast_period |
Days to predict | 365 | One year forecast |
- Yearly Seasonality: Enable for annual patterns
- Weekly Seasonality: Enable for weekly patterns
- Daily Seasonality: Enable for daily patterns
- Trend: Long-term growth or decline patterns
- Seasonality: Recurring patterns (weekly, monthly, yearly)
- Holidays: Special event effects
- Confidence Intervals: Uncertainty ranges around predictions
- MAE (Mean Absolute Error): Average absolute prediction error
- RMSE (Root Mean Squared Error): Square root of average squared errors
- MAPE (Mean Absolute Percentage Error): Percentage error representation
- MSE (Mean Squared Error): Average squared prediction errors
- Lower metric values indicate better model performance
- Wider confidence intervals suggest higher uncertainty
- Strong seasonality shows clear recurring patterns
- Anomalies may indicate special events or data issues
- Streamlit: Web application framework
- Plotly: Interactive visualizations
- Custom CSS: Styled user interface
- Prophet: Facebook's forecasting library
- Pandas: Data manipulation and analysis
- NumPy: Numerical computations
- Scikit-learn: Additional machine learning utilities
SalesForecastAI/
├── app.py # Main application file
├── requirements.txt # Python dependencies
├── components/ # UI components
│ ├── data_upload.py # Data upload functionality
│ ├── forecast.py # Forecasting interface
│ ├── analysis.py # Analysis features
│ ├── help.py # Help documentation
│ └── sidebar.py # Settings sidebar
├── utils/ # Utility functions
│ ├── data_processing.py # Data validation and processing
│ ├── forecasting.py # Prophet model wrapper
│ ├── metrics.py # Performance calculations
│ └── visualization.py # Chart creation
└── styles/ # Custom styling
└── custom.py # CSS styles
Installation Problems
# If you encounter dependency issues:
pip install --upgrade pip
pip install -r requirements.txt --force-reinstall
Data Upload Errors
- Ensure CSV format is correct
- Check date format (YYYY-MM-DD)
- Verify sales column contains numeric values
- Remove any empty rows or invalid data
Forecast Generation Issues
- Ensure sufficient historical data (at least 1 year recommended)
- Try adjusting model parameters in sidebar
- Check for data quality issues or outliers
Performance Issues
- Reduce forecast period for faster processing
- Simplify model parameters
- Use smaller datasets for testing
- Provide More Data: Longer history improves accuracy
- Clean Your Data: Remove outliers and errors
- Include Relevant Variables: Add factors that influence sales
- Regular Updates: Refresh forecasts with new data
- Validate Results: Compare predictions with actual outcomes
- Consistent Formatting: Use standardized date formats
- Handle Missing Data: Fill gaps or remove incomplete records
- Document Changes: Note any business events or anomalies
- Quality Checks: Verify data accuracy before uploading
