π½οΈ Forecasting School Meal Production Costs: A Comparative Study of Machine Learning and Deep Learning Time-Series Models
This project develops a time-series forecasting system for Fairfax County Public Schools (FCPS) to estimate daily meal production costs and analyze waste-related patterns. It compares multiple machine learning and deep learning models-including LSTM, GRU, XGBoost, Linear Regression, and Feed-Forward Neural Networks and visualizes the results through an interactive Streamlit dashboard.
The goal is simple: π Reduce food waste, improve planning, and optimize meal production costs across the district.
- Overview
- Dataset Workflow
- Key Features
- System Architecture
- Model Pipeline
- Getting Started
- Dashboard (Streamlit App)
- API Endpoints
- Troubleshooting
- Research & Performance
- Technology Stack
- Contributing
- License
- Acknowledgments
Our pipeline transforms raw FCPS Production Records + POS data β clean, structured forecasting dataset.
β Reads dozens of messy FCPS breakfast & lunch HTML files
β Auto-detects school sections
β Extracts production, leftover, planned, served, discarded values
β Cleans currencies, percentages, and item names
β Standardizes headers
Outputs generated:
src/Data/Output/breakfast_combined.csvsrc/Data/Output/lunch_combined.csvsrc/Data/Output/meals_combined.csv
β Cleans $ & % β float
β Converts & sorts dates
β Handles missing values
β Outlier removal using 99th percentile
β Encodes meal types
β Produces final ML-ready dataset for:
- Univariate Forecasting
- Multivariate Forecasting
- Streamlit Dashboard
| Column | Description |
|---|---|
| school_name | FCPS school |
| meal_type | breakfast/lunch |
| date | daily record |
| served_total | meals served |
| planned_total | planned meals |
| discarded_total | wasted meals |
| left_over_total | leftover meals |
| production_cost_total | $$ spent per item-day |
- LSTM & GRU deep learning models
- Univariate forecasting (district-level daily time-series)
- Multivariate forecasting (served/planned/discarded/leftovers β cost)
- Predict discarded + leftover quantities
- Waste ratio analytics
- Identify high-waste menu items
- Predict production cost for next 10 days
- Scenario modeling using βWhat-Ifβ adjustments
- School-wise filtering
- Cost trends
- Waste ratio analysis
- What-if ML predictions
- Benchmark model comparison
- Linear Regression
- XGBoost
- Feed-Forward Neural Network
- GRU & LSTM
ββββββββββββββββββββββββββββ
β Raw FCPS HTML Files β
βββββββββββββββββ¬βββββββββββ
β
(HTML Parser + Normalizer)
β
βΌ
ββββββββββββββββββββββββββββ
β meals_combined.csv β
βββββββββββββββββ¬βββββββββββ
β
(Data Preprocessing)
β
ββββββββββββββΌββββββββββββββββ¬βββββββββββββββ
βΌ βΌ βΌ
Univariate Multivariate Benchmark
LSTM GRU Models
β β β
βββββββββ¬ββββββ΄ββββββββ¬βββββββ
βΌ βΌ
Forecasts Performance Charts
β β
βββββββββ¬βββββ
βΌ
Streamlit Dashboard
---
Uses district-wide daily production costs:
β‘οΈ [Cost(tβ7) β¦ Cost(tβ1)] β Predict Cost(t)
Models:
- LSTM
- GRU
- Feedforward baseline
- XGBoost
- Linear Regression
Features:
- served_total
- planned_total
- discarded_total
- left_over_total
Target:
- production_cost_total
Models:
- Linear Regression
- XGBoost
- FeedForwardNN
- GRU (sequence-based, school-wise)
- LSTM
You can install the following modules through pip
pip install -r src/requirements.txtInstall:
- Python 3.10+
- pip
- PyTorch
- XGBoost
- pandas
- numpy
- beautifulsoup4
- lxml
- pdfplumber
- PyPDF2
- tqdm
- statsmodels
- scikit-learn
- matplotlib
- streamlit
Important source files:
src/component/preprocess.py
src/component/EDA.py
src/component/univariate/
src/component/multivariate/
src/tests/combine_csv.py
src/maincode/main.py
python src/tests/combine_csv.py
This script:
- Reads FCPS breakfast & lunch HTML production records
- Extracts β served, planned, discarded, leftover, cost
- Cleans currency & % values
- Standardizes headers
- Generates:
src/Data/Output/breakfast_combined.csv
src/Data/Output/lunch_combined.csv
src/Data/Output/meals_combined.csv
Before opening the dashboard, you must generate the data:
python src/maincode/main.py
LSTM Models: https://drive.google.com/drive/folders/1daVVcrvS2u6rFBcKG_RjkQJh6Q19z4P7?usp=drive_link
GRU Models: https://drive.google.com/drive/folders/1KtWlLppDeVkl30KRoWk2DoWPzYHRoRkN?usp=drive_link
Comparing Models: https://drive.google.com/drive/folders/1GFUuX3pHYzUkceX-JBETsv6FtPSd_x0M?usp=drive_link
Our interactive FCPS Meal Analytics Dashboard provides real-time insights into school meal operations. Run the full interactive dashboard
streamlit run demo/app.py
βββ demo
β βββ fig
β β βββ Video.mp4
β β
β βββ images
β β βββ multivariate_plots
β β β βββ GRU.png
β β β βββ LSTM.png
β β β βββ fnn_model.png
β β β βββ linear_regression.png
β β β βββ xgboost_model.png
β β β
β β βββ univariate_plots
β β βββ GRU.png
β β βββ LSTM.png
β β βββ LSTM_train_test_forecast_example.png
β β βββ fnn_model.png
β β βββ linear_regression.png
β β βββ xgboost_model.png
β β
β βββ .gitkeep
β βββ app.py
β
βββ presentation
β βββ Capstone_Presentation_Group9.pptx
| βββ Capstone_Presentation_Group9.pdf
β βββ .gitkeep
β
βββ reports
β βββ Latex_report
β β βββ fig
β β βββ File_Setup.tex
β β βββ Report_PDF.pdf
β β βββ references.bib
β β βββ word_report.text
β β
β βββ Markdown_Report
β β βββ .gitkeep
β β
β βββ Progress_Report
β β βββ Markdown_CheatSheet
β β β βββ Markdown1.pdf
β β β βββ Markdown2.pdf
β β β βββ Markdown3.pdf
β β β βββ Markdown4.pdf
β β β
β β βββ Progress_Report.md
β β βββ img_2.png
β β
β βββ Word_Report
β βββ Final Report.docx
β
βββ research_paper
β βββ Latex
β β βββ fig
β β β βββ images
β β βββ mybib.bib
β β βββ research_paper.pdf
β β βββ research_paper.tex
β β
β βββ Word
β β βββ Conference-template-A4.doc
β β
β βββ .DS_Store
β
βββ src
βββ Data
β βββ Html
β β βββ May 2025 Breakfast production records
β β βββ May 2025 Lunch production records
β β
β βββ Output
β βββ breakfast_combined.csv
β βββ lunch_combined.csv
β βββ meals_combined.csv
β
βββ component
β βββ EDA.py
β βββ preprocess.py
β β
β βββ multivariate
β β βββ model.py
β β βββ plot.py
β β βββ training.py
β β βββ utils.py
β β
β βββ univariate
β βββ comparing_model.py
β βββ forecasting.py
β βββ model.py
β βββ plot.py
β βββ training.py
β βββ utils.py
β
βββ maincode
β βββ main.py
β
βββ results
β βββ all_school_meal_forecasts.csv
β
βββ tests
β βββ combine_csv.py
β βββ multivariate_main.py
β
βββ .gitkeep
βββ requirements.txt
Although this project does not use external REST APIs, the internal Streamlit dashboard relies on several Python-based API-like functions that power forecasting and analysis.
| Function | Description | Location |
|---|---|---|
forecast_future_dates() |
Predicts next k days using trained LSTM/GRU models | src/forecasting.py |
load_and_aggregate_district() |
Loads CSV + cleans + aggregates district production cost | src/utils.py |
safe_time_split() |
Chronological train-test split for time-series | src/utils.py |
TimeSeriesDataset |
Creates sliding windows for univariate LSTM/GRU | src/utils.py |
ForecastingModel |
LSTM/GRU model class | src/model.py |
FeedForwardRegressor |
Baseline neural network model | src/model.py |
forecast_all_models_in_folder() |
Runs forecasts for every school (batch mode) | app.py |
school_loss_analysis() |
Detects schools with high loss or wastage | app.py |
| Action | Trigger Button | What Happens |
|---|---|---|
| Run Forecast | Run Forecast | Loads all LSTM/GRU models and predicts next k days |
| Compare Models | Compare LSTM vs GRU | Runs both folders β compares total cost curves |
| AI Recommendations | AI Recommendations | Suggests waste reduction strategies |
| Wastage Heatmap | Auto-loaded | Creates weekday-based discarded food heatmap |
| School-Level View | Dropdown Filters | Filters graphs/tables by school + meal type |
Quick solutions to the most common issues:
| Issue | Cause | Simple Fix |
|---|---|---|
| Empty CSV after parsing | Wrong HTML folder path | Check breakfast/lunch folder paths before running preprocess_html.py |
| Date errors / NaNs | FCPS dates use mixed formats | Use dayfirst=True in pd.to_datetime() (already used in code) |
| LSTM/GRU model not loading | Wrong .pth path |
Ensure model file is inside: univariate/LSTM_models/ or univariate/GRU_models/ |
| Streamlit blank page | Cached old data | Run: streamlit cache clear |
| XGBoost import error | Not installed | pip install xgboost |
| Very high forecast values | Outliers in cost | 99th percentile cleaning already includedβrecheck preprocessing |
| Training too slow | Model too big | Reduce HIDDEN_DIM from 256 β 128 |
| Forecast shows empty for a school | School name mismatch | Filename uses _ (e.g., Aldrin_Elementary), CSV uses spaces β ensure both match |
| Heatmap blank | Non-numeric waste columns | Convert with pd.to_numeric(errors='coerce').fillna(0) |
| βForecast failedβ error | Not enough rows for that school | Check if subset CSV has enough data; retrain if needed |
| Port already in use (Streamlit) | Another app running | Run: lsof -i :8501 β kill -9 <PID> |
These models predict production_cost_total using only past cost values (sliding window of 7 days).
| Model | RMSE | RΒ² | Notes |
|---|---|---|---|
| LSTM | β Best | High | Learns long-term temporal patterns extremely well |
| GRU | Very Good | High | Faster than LSTM, stable performance |
| XGBoost | Medium | Medium | Strong non-linear baseline, but not sequence-aware |
| Feed-Forward NN (FNN) | Medium | Medium | Good baseline but ignores temporal structure |
| Linear Regression | Poor | Low | Cannot model sequential dependencies |
These models use:
served_totalplanned_totaldiscarded_totalleft_over_total
to predict:
production_cost_total
| Model | Performance | Notes |
|---|---|---|
| GRU (Sequence Model) | β Best (if metrics show this) | Captures school-wise temporal patterns across multiple features |
| LSTM (Sequence Model) | β Best / Very Strong | Multivariate LSTM trained on same features; stable long-range learning |
| XGBoost | Strong | Excellent for structured/tabular data |
| Feed-Forward NN | Good | Learns non-linear interactions but not sequence structure |
| Linear Regression | Baseline | Limited for multi-feature temporal data |
- Both multivariate LSTM and GRU clearly outperform classical models (XGBoost, FNN, Linear Regression).
- Including served, planned, discarded, and leftover meals improves cost prediction compared to cost-only models.
- Sequence models (LSTM/GRU) handle school-level temporal behavior much better than non-sequence models.
- Outlier removal and proper preprocessing stabilize forecasts and reduce noise.
| Category | Technologies |
|---|---|
| π€ Machine Learning | PyTorch Β· XGBoost Β· Scikit-Learn |
| π§ Deep Learning | LSTM Β· GRU Β· FeedForwardNN |
| π₯οΈ Dashboard | Streamlit Β· Plotly Express |
| π§Ή Data Processing | Pandas Β· NumPy Β· BeautifulSoup Β· lxml |
| π Visualization | Matplotlib Β· Seaborn |
| π§ͺ Evaluation | MSE Β· RMSE Β· RΒ² Β· MAE |
| π Utilities | Pickle Β· Glob Β· Pathlib Β· OS |
| π§ Version Control | Git Β· GitHub |
| π Deployment | Local Machine Β· Streamlit Cloud |
| π» Language | Python |
We welcome contributions from developers, students, and researchers. Steps:
# Create a feature branch
git checkout -b feature/my-feature
# Make changes and commit
git commit -m "Added new improvement"
# Push to repo
git push origin feature/my-feature
Then open a Pull Request on GitHub.
This project is licensed under the MIT License. You are free to use, modify, and distribute the software with proper attribution.
Special thanks to the contributors who made this project possible:
β’ Dr. Amir Jafari β Project Guidance (GWU)
β’ Fairfax County Public Schools (FCPS) β For providing production record structures
β’ Open-source community β PyTorch, Streamlit, XGBoost
β’ Team Members β Areena, Chaya, Varshith