A full-stack time series forecasting and anomaly detection application with AI-powered insights. Especially curated for non-tech people so that they can leverage the benefits of Data Science. Forecast uses multiple statistical models to predict future trends and automatically detects outliers in your data.
flowchart TD
A[Start] --> B["Input Data<br/>(API / CSV / UI)"]
B --> C["Data Cleaning & Validation"]
C --> D[Feature Extraction]
D --> D1[Trend]
D --> D2[Seasonality]
D --> D3[Noise]
D --> E[Select Model]
E -->|Stable / Noisy| F[Moving Average]
E -->|Trend Detected| G[Linear Trend]
E -->|Seasonality Detected| H[Holt-Winters]
F --> I[Generate Forecast]
G --> I
H --> I
I --> J["Estimate Uncertainty<br/>(Residual Std)"]
J --> K["Create Prediction Range<br/>(Lower & Upper Bounds)"]
I --> L["Detect Anomalies<br/>(Deviation Check)"]
I --> M["Compare with Baseline<br/>(MAPE)"]
I --> N[Generate Insights]
N --> O["LLM Explanation<br/>(Simple Language)"]
K --> P[Final Output]
L --> P
M --> P
O --> P
P --> Q["Display Results<br/>(Charts + Alerts)"]
Q --> R[End]
-
Multiple Forecasting Models
- Moving Average forecasting
- Linear Trend prediction
- Holt-Winters Exponential Smoothing (with seasonal decomposition)
- Intelligent model selection based on data characteristics
-
Anomaly Detection
- Statistical anomaly detection using z-score (2Ο threshold)
- Automatic identification of outliers in time series data
-
AI-Powered Insights
- Integration with Google Generative AI for natural language insights
- Query-based analysis of forecasts and data patterns
- Automatic anomaly explanation and recommendations
-
Flexible Data Input
- Direct API calls with numerical arrays
- CSV file uploads with targeted column selection
- Support for large datasets with built-in validation
-
Feature Analysis
- Automatic feature extraction (seasonality, trend strength, noise level)
- Model selection based on data characteristics
- Performance metrics (MAPE) for model evaluation
-
Modern UI
- React + TypeScript frontend
- Responsive design with Tailwind CSS
- Real-time forecasting visualization
- Interactive data upload and analysis
ML explores hidden patterns, LLM explains it
- Python 3.13+
- Node.js 18+
- npm or yarn
- Google Generative AI API key (for LLM features)
- Clone the repository and navigate to the project directory:
cd d:\forecast- Install dependencies and set up the virtual environment:
Option A: Using uv (Recommended)
uv syncOption B: Traditional (pip + venv)
python -m venv .venv
# On Windows:
.\.venv\Scripts\Activate.ps1
# On macOS/Linux:
source .venv/bin/activate
pip install -r requirements.txt- Create a
.envfile in the project root by checking.env.exampleand add your Google Generative AI API key:
cp .env.example .env
# Edit .env and add your API key- Navigate to the frontend directory:
cd frontend- Install Node dependencies:
npm install- Return to the project root:
cd ..# Make sure you're in the project root
# Option A: Using uv
uv run uvicorn backend.main:app --reload
# Option B: Traditional (ensure your venv is activated)
uvicorn backend.main:app --reloadThe API will be available at http://localhost:8000
- API documentation:
http://localhost:8000/docs
In a new terminal:
cd frontend
npm run devThe frontend will be available at http://localhost:5173
Make a forecast with a data array and optional query.
Request:
{
"values": [10, 12, 15, 14, 16, 18, 20, 19, 22],
"query": "What trend do you see in this data?"
}Response:
{
"forecast": [...],
"anomalies": [...],
"features": {...},
"selected_model": "holt_winters",
"insights": "..."
}Upload a CSV file and forecast a specific column.
Form Data:
file: CSV file (multipart/form-data)target_column: Column name to forecastuser_query: Optional query for insights
Response: Same as /forecast endpoint
forecast/
βββ backend/
β βββ main.py # FastAPI application and endpoints
β βββ pipeline.py # Data processing pipeline
β βββ models.py # Forecasting models (moving average, linear trend, Holt-Winters)
β βββ anomaly.py # Anomaly detection logic
β βββ features.py # Feature extraction for data analysis
β βββ graph.py # LangChain/agentic workflow for insights
β βββ llm.py # Google Generative AI integration
β βββ insight.py # Insight generation
β βββ config.py # Configuration settings
βββ frontend/
β βββ src/
β β βββ components/ # React components
β β βββ App.tsx # Main app component
β β βββ main.tsx # React entry point
β β βββ index.css # Global styles
β βββ public/ # Static assets
β βββ vite.config.ts # Vite configuration
β βββ package.json # Frontend dependencies
βββ tests/
β βββ test_api.py # API endpoint tests
β βββ test_data.csv # Test dataset
β βββ seasonal_test_data.csv
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project metadata and config
βββ README.md # This file
| Model | Best For | Characteristics |
|---|---|---|
| Moving Average | Noisy data, high noise levels | Simple, smooths out fluctuations |
| Linear Trend | Trending data | Captures consistent directional change |
| Holt-Winters | Seasonal data, strong trends | Captures trends and seasonality |
The system automatically selects the best model based on:
- Seasonality strength (>0.5 β Holt-Winters)
- Trend strength (>0.5 β Holt-Winters)
- Noise level (>0.6 β Moving Average)
Run the test suite using pytest:
# Option A: Using uv
uv run pytest tests/ -v
# Option B: Traditional (ensure your venv is activated)
pytest tests/ -vTest files include:
test_api.py- API endpoint tests- Sample test data files for validation
- Backend server runs with
--reloadflag for hot reloading - Edit files in
backend/and changes will automatically reload
- Frontend runs with Vite dev server for instant updates
- Watch mode automatically rebuilds TypeScript and triggers browser refresh
Lint the frontend code:
cd frontend
npm run lintBuild for production:
# Backend runs as-is with uvicorn
# Frontend
npm run build- FastAPI - Web framework
- pandas - Data manipulation
- NumPy - Numerical computing
- scikit-learn - Machine learning models
- statsmodels - Time series analysis (Holt-Winters)
- scipy - Scientific computing
- google-generativeai - LLM integration
- python-dotenv - Environment variable management
- React 18 - UI library
- TypeScript - Type-safe JavaScript
- Vite - Build tool and dev server
- Tailwind CSS - Utility-first CSS
- shadcn/ui - Component library
- Lucide React - Icon library
- Motion - Animation library
The application integrates Google Generative AI to:
- Explain forecast trends in natural language
- Answer questions about data patterns
- Provide recommendations based on anomalies
- Generate insights from statistical analysis
The system validates input data to ensure quality forecasts:
- Rejects non-numeric columns
- Removes NaN values automatically
- Ensures minimum data length requirements
- Sanitizes responses to prevent JSON serialization errors
- Handles edge cases (zero-variance data, very small datasets)
- Zero-Variance Data: Features module guards against zero-variance inputs to prevent NaN/inf values
- Small Datasets: Models default to moving average for very small datasets (β€5 values)
- JSON Serialization: Non-finite float values (NaN, inf) are sanitized to null before response
Create a .env file in the project root by checking .env.example:
cp .env.example .envMake sure to add your API keys as needed in the .env file:
# Google Generative AI
GOOGLE_API_KEY=your_api_key_here- Use
uvicornwith production settings:uvicorn backend.main:app --host 0.0.0.0 --port 8000
- Build for production:
cd frontend && npm run build
- Serve the
dist/folder with your preferred web server
Contributions are welcome! Please feel free to submit a Pull Request.
For issues, questions, or feedback, please open an issue on the repository.