Downloads · 30 days
0
akshara-ns/snack-category-automl
snack-category-automl is a tabular classification model from akshara-ns. Use it for the tabular classification task on the model card, and read the license before you ship it in a product. It is set up for sklearn. The card lists the license as apache-2.0.
Predicts which of five snack categories a packaged product belongs to, using only the eight numbers printed on its Nutrition Facts panel.
Downloads · 30 days
0
Access
Public
Updated Sep 20, 2026
Repo size
7.6 KB
Likes
0
Public
Click a slice to open those files.
.joblib7.6 KB · 45%
From the Hugging Face model README
Predicts which of five snack categories a packaged product belongs to, using only the eight numbers printed on its Nutrition Facts panel.
Built for24-679 Designing & Prototyping AI Systems. Selected by an Optuna AutoML search over six scikit-learn model families.
Intended. Demonstrating AutoML on a small tabular dataset; a reference implementation of leakage-aware evaluation when a dataset is mostly synthetic.
Not intended. Nutrition advice, dietary guidance, food-safety decisions, regulatory labelling, or any consumer-facing product. The model is trained on 30 real snacks. It has no basis for generalising to the packaged-food market.
shanexf/packaged-snack-nutrition-data, collected by a classmate
for HW1. Used as published; I am not the dataset author.candy, chips, cookies, crackers, granola_bars — 6 real snacks each.I built my own split with two rules:
parent_id, second_parent_id). A row joins a split only if
both parents are on that side; 189 rows straddle the boundary and were dropped.| Split | Parents | Rows |
|---|---|---|
| Training pool | 20 (4/class) | 246 |
| Test — all | 10 (2/class) | 90 |
| Test — real snacks only | 10 | 10 |
| Dropped (straddling) | — | 93 |
Input is 8 floats in this exact order:
['serving_size_g', 'servings_per_container', 'calories', 'total_fat_g', 'sodium_mg', 'carbs_g', 'sugar_g', 'protein_g']
Preprocessing is StandardScaler, bundled inside the saved Pipeline. Provenance columns (source_id, parent_id, augmentation, …) are deliberately
excluded; they encode the augmentation structure and would leak the label.
| Engine | optuna==5.0.0, TPE sampler, seed 24679 |
| Budget | 150 trials / 600s wall-clock cap — 150 trials ran |
| Search space | model family × its hyperparameters, jointly (logreg, RF, extra-trees, HistGB, SVM, kNN) |
| Validation | 4-fold CV, folds grouped on parent snack, both-parents rule applied per fold |
| Objective | macro-F1, scored on real rows only |
| Selected | svm — {'svc_C': 8.55142672640755, 'svc_kernel': 'linear', 'svc_gamma': 'auto'} |
A validation fold's synthetic rows are jittered copies of that same fold's real snacks, so scoring on them rewards a model for memorising augmentation artefacts. Running the identical search both ways:
| CV scoring | CV macro-F1 | Test (all) macro-F1 | Test (real) macro-F1 |
|---|---|---|---|
| All rows | 0.8788 | 0.7333 | 0.7333 |
| Real rows only | 0.8167 | 0.7531 | 0.8933 |
Scoring on all rows gives a higher CV score that does not survive the test set. The real-rows-only search was selected.
| Split | n | macro-F1 | accuracy |
|---|---|---|---|
| CV (model selection) | — | 0.8167 | — |
| Test — all rows | 90 | 0.7531 | 0.8556 |
| Test — real snacks | 10 | 0.8933 | 0.9 |
Bootstrap 95% CI on the real-snack macro-F1 (5000 resamples): 0.600 – 1.000. The interval is wide because n = 10. Quote the interval, not the point estimate.
Per-class breakdown (test, all rows):
precision recall f1-score support
candy 1.000 0.083 0.154 12
chips 0.929 1.000 0.963 26
cookies 0.522 1.000 0.686 12
crackers 1.000 0.929 0.963 28
granola_bars 1.000 1.000 1.000 12
accuracy 0.856 90
macro avg 0.890 0.802 0.753 90
weighted avg 0.916 0.856 0.823 90
Nutrition data invites misuse as dietary guidance. This model classifies a marketing category and says nothing about whether a food is healthy, suitable for any diet, or safe for any allergy.
Hardware / compute budget: Google Colab CPU runtime (no accelerator). The full search completes in well under the 600s cap; total notebook runtime is a few minutes.
import joblib, numpy as np
from huggingface_hub import hf_hub_download
pipe = joblib.load(hf_hub_download("akshara-ns/snack-category-automl", "model.joblib"))
# serving_size_g, servings_per_container, calories, total_fat_g,
# sodium_mg, carbs_g, sugar_g, protein_g
x = np.array([[28, 6, 150, 9, 160, 16, 0.5, 1]])
print(pipe.predict(x)) # -> e.g. ['chips']
Dataset by a 24-679 classmate: shanexf/packaged-snack-nutrition-data.
Model by Akshara N.S..
AI-usage disclosure. Generative AI assisted in drafting the notebook code and this card; I reviewed, ran, corrected, and edited all of it. Every number above is produced by executing the notebook. The task definition, split design, search space, and interpretation are mine.
License: Apache-2.0. The dataset remains under the license stated on its own Hub page.