| Endpoint | Description | URL |
|---|---|---|
| 🌐 Base URL | Root of the API | https://web-production-e2163.up.railway.app |
| 🩺 Health Check | API health status | https://web-production-e2163.up.railway.app/health |
| 📈 Monthly Prediction | Predict expenses for a given month | https://web-production-e2163.up.railway.app/predict/month?year=2025&month=10 |
| 🧮 Model Metrics | Compare model performance | https://web-production-e2163.up.railway.app/metrics |
| 🧠 Model Retrain (POST) | Retrain the model dynamically | https://web-production-e2163.up.railway.app/retrain |
| 📊 Forecast Plot | Visualize future expense forecast trends | https://web-production-e2163.up.railway.app/plots/forecast |
| 📉 Historical Trend Plot | View historical expense data visualization | https://web-production-e2163.up.railway.app/plots/history |
| Feature | Description | URL |
|---|---|---|
| 🍽️ Meal Expense Dashboard | Visual interface built on top of this API | https://meal-app-delta-tan.vercel.app/predictions |
This UI interactively displays forecast results, monthly expense breakdowns, and helps plan next month's meal budget using data served from this API.
Meal Expense Forecast API is a Machine Learning–driven system built using FastAPI that predicts daily and monthly meal expenses from historical company data.
It’s optimized to help with:
- Budget forecasting 📊
- Trend visualization 📈
- Real-time predictions via REST API ⚙️
| Layer | Technology |
|---|---|
| Backend | FastAPI (Python 3.11) |
| ML Models | RandomForestRegressor, Prophet |
| Data | Pandas, NumPy |
| Visualization | Matplotlib / Plotly |
| Deployment | Railway.app |
| Environment | .env for configuration |
# Clone the repo
git clone https://github.com/<your-username>/meal-expense-forecast-api.git
cd meal-expense-forecast-api
# Create virtual environment
python -m venv .venv
.\.venv\Scripts�ctivate # For Windows
# Install dependencies
pip install -r requirements.txt
# Train model
python -m src.train --csv ./data/expenses.csv --model ./models/expense_rf.pkl
# Run FastAPI server
uvicorn app.main:app --reload --port 8000
# Open docs
http://127.0.0.1:8000/docs| Model | MAE | RMSE | R² | MAPE |
|---|---|---|---|---|
| RandomForest (Daily) | 159.22 | 251.56 | 0.990 | 2.83% |
| RandomForest (Monthly) | 5659.49 | 5660.82 | 0.523 | 3.04% |
| Prophet | 1387.70 | 2006.88 | 0.379 | 29.38% |
🏆 Best Model: RandomForest (Daily)
GET → https://web-production-e2163.up.railway.app/health
GET → https://web-production-e2163.up.railway.app/predict/month?year=2025&month=10
POST → https://web-production-e2163.up.railway.app/retrain
Body (JSON):
{
"csv_path": "./data/expenses.csv"
}- Push this repo to GitHub.
- Create new project on Railway.
- Connect to your GitHub repo.
- Add Environment Variables:
DATA_CSV=./data/expenses.csv MODEL_PATH=./models/expense_rf.pkl TIMEZONE=Asia/Dhaka
- Set Start Command:
uvicorn app.main:app --host 0.0.0.0 --port $PORT - Deploy 🚀
Developed by: Phoenix (Nayan)
🔗 GitHub: https://github.com/onlynayan
💡 “Smarter budgeting starts with intelligent forecasting.”