Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

435 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍽️ 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.

🏷️ Badges


πŸ“‹ Table of Contents


πŸ”„ Dataset Workflow

Our pipeline transforms raw FCPS Production Records + POS data β†’ clean, structured forecasting dataset.


1️⃣ HTML β†’ CSV Parser

βœ” 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.csv
  • src/Data/Output/lunch_combined.csv
  • src/Data/Output/meals_combined.csv

**2️⃣ Data Cleaning & Preprocessing **

βœ” 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

⭐ Final Dataset Columns

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

🎯 Key Features

🍽️ 1. Meal Demand Forecasting

  • LSTM & GRU deep learning models
  • Univariate forecasting (district-level daily time-series)
  • Multivariate forecasting (served/planned/discarded/leftovers β†’ cost)

♻️ 2. Waste Optimization

  • Predict discarded + leftover quantities
  • Waste ratio analytics
  • Identify high-waste menu items

πŸ’² 3. Cost Forecasting

  • Predict production cost for next 10 days
  • Scenario modeling using β€œWhat-If” adjustments

πŸ“Š 4. Interactive Streamlit Dashboard

  • School-wise filtering
  • Cost trends
  • Waste ratio analysis
  • What-if ML predictions
  • Benchmark model comparison

🧠 5. Machine Learning Benchmarking

  • Linear Regression
  • XGBoost
  • Feed-Forward Neural Network
  • GRU & LSTM

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Raw FCPS HTML Files   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
     (HTML Parser + Normalizer)
                β”‚
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    meals_combined.csv    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
       (Data Preprocessing)
                β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β–Ό            β–Ό               β–Ό
Univariate   Multivariate     Benchmark  
   LSTM          GRU           Models
   β”‚             β”‚               β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
           β–Ό             β–Ό
      Forecasts   Performance Charts
           β”‚             β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                   β–Ό
        Streamlit Dashboard


---

πŸ€– Model Pipeline

πŸ“Œ Univariate Forecasting (LSTM / GRU)

Uses district-wide daily production costs:

➑️ [Cost(tβˆ’7) … Cost(tβˆ’1)] β†’ Predict Cost(t)

Models:

  • LSTM
  • GRU
  • Feedforward baseline
  • XGBoost
  • Linear Regression

πŸ“Œ Multivariate Forecasting

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

πŸš€ Getting Started

βœ”οΈ Prerequisites

Module Installation

You can install the following modules through pip

pip install -r src/requirements.txt

Install:

  • Python 3.10+
  • pip
  • PyTorch
  • XGBoost
  • pandas
  • numpy
  • beautifulsoup4
  • lxml
  • pdfplumber
  • PyPDF2
  • tqdm
  • statsmodels
  • scikit-learn
  • matplotlib
  • streamlit

🌱 Environment Setup

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         

HTML β†’ CSV Preprocessing

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

Run the Data Pipeline

Before opening the dashboard, you must generate the data:

python src/maincode/main.py

Download Instructions Navigate to:

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

βœ… πŸ“Š Dashboard (Streamlit App)

Our interactive FCPS Meal Analytics Dashboard provides real-time insights into school meal operations. Run the full interactive dashboard

streamlit run demo/app.py

Folder Structure

β”œβ”€β”€ 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

πŸ“‘ API Endpoints

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.

πŸ”§ Internal Model Endpoints

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

πŸ–₯️ Dashboard-Level Actions (Triggered in Streamlit)

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

πŸ”§ Troubleshooting

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>

πŸ“Š Research & Performance

1️⃣ Univariate Forecasting Results (Cost-Only Models)

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

2️⃣ Multivariate Forecasting Results (School-Level Features)

These models use:

  • served_total
  • planned_total
  • discarded_total
  • left_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

πŸ—οΈ Key Findings (Short)

  • 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.

🧰 Technology Stack

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

βœ… 🀝 Contributing

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.

βœ… πŸ“„ License

This project is licensed under the MIT License. You are free to use, modify, and distribute the software with proper attribution.

βœ… πŸ™ Acknowledgments

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages