This project applies a data science segmentation approach to food engineering data using Open Food Facts product information.
The main goal of the project is to analyze food products based on nutritional values such as sugar, fat, salt, protein, and additive count. These values are converted into categorical features, then combined into food profiles. Finally, the food profiles are segmented according to a custom nutrition risk score.
This project is inspired by previous segmentation-based data science projects.
Persona Project:
COUNTRY + SOURCE + SEX + AGE_CAT -> PRICE_SEGMENT
Planets Project:
METHOD + YEAR_CAT + NUMBER_CAT -> DISTANCE_SEGMENT
Food Engineering Adaptation:
CATEGORY + SUGAR_CAT + FAT_CAT + SALT_CAT + ADDITIVE_CAT -> NUTRITION_SEGMENT
The data is retrieved from the Open Food Facts API.
If the Open Food Facts API is temporarily unavailable, the script uses a small educational fallback dataset to continue the project workflow.
- Python
- pandas
- NumPy
- requests
- Open Food Facts API
- GitHub
| Feature | Description |
|---|---|
| product_name | Name of the food product |
| categories | Product category |
| sugars_100g | Sugar amount per 100g |
| fat_100g | Fat amount per 100g |
| salt_100g | Salt amount per 100g |
| proteins_100g | Protein amount per 100g |
| additives_n | Number of additives |
| nutrition_grade | Nutrition grade if available |
The numerical nutritional values are converted into categorical variables.
| Original Feature | Created Category |
|---|---|
| sugars_100g | SUGAR_CAT |
| fat_100g | FAT_CAT |
| salt_100g | SALT_CAT |
| additives_n | ADDITIVE_CAT |
Example food profile:
SNACKS_VERY_HIGH_SUGAR_VERY_HIGH_FAT_MEDIUM_SALT_MEDIUM_ADDITIVE
A custom nutrition risk score is calculated using sugar, fat, salt, additive count, and protein values.
NUTRITION_RISK_SCORE = ( sugars_100g * 1.5 + fat_100g * 1.2 + salt_100g * 10 + additives_n * 2 - proteins_100g * 0.5 )
This score is created for educational data science practice. It is not an official health score.
Food profiles are grouped and segmented based on their average nutrition risk score.
| Segment | Meaning |
|---|---|
| A | Highest risk profile |
| B | High risk profile |
| C | Medium risk profile |
| D | Lower risk profile |
The project creates two CSV files in the outputs folder:
outputs/open_food_facts_dataset.csv
outputs/food_profile_segments.csv
Install the required libraries:
pip install -r requirements.txt
Run the Python script:
python open_food_facts_segmentation.py
This project demonstrates how food engineering data can be analyzed using Python, API usage, feature engineering, custom scoring, and segmentation logic.
- Add visualizations for sugar, fat, salt, and additive distributions
- Add a machine learning model for nutrition grade prediction
- Add a Streamlit dashboard
- Analyze specific product categories such as dairy, snacks, beverages, or bakery products
- Compare products by country or brand