Skip to content

dataforgoodfr/batch5_phenix_happymeal

Repository files navigation

Phenix project - Happy meal algorithm

The main goal of this repository is to create balanced meals from a list of products

Understanding our algorithm

Overview of the balanced meal generation process

In the following workflow, EAN means European Article Number and OFF Open Food Facts.

Image

(The source code of this workflow can be found here)

Matching

We used the Naive Bayes method in order to automatically assign categories to articles according to their names.

Classifier

We used the Random Forest method (40 trees) to automatically assign categories to articles according to their nutrients (6 features).

Defining weights in grams

This algorithm works as follow:

  • If the quantity is mentioned in OFF, then converts the quantity in grams
    • if not, then compute the average of article's category quantities
  • If the article is rice, semolina, pasta or instant mashed potatoes, then multiply by a specific coefficient

Optimizer

Description can be found here.

Reallocating remaining articles

add a description here

Requirements

The numpy and openfoodfacts packages are required to properly use the repo. Tested on the following version:

import sys
import numpy, openfoodfacts
print('Python %s' % '.'.join(map(str, sys.version_info[:3])))
print('Numpy %s, Openfoodfacts %s' % (numpy.__version__, openfoodfacts.__version__))
Python 3.6.5
Numpy 1.15.0, Openfoodfacts 0.1.0

How to use it

Depending on the feature you wish to test, you may need an Internet connection (product information)

Product information

Pass a barcode (EAN) as argument of the demo script:

python product_info_demo.py 3392460480827

Meal balancing

Run a simulation with the demo script similarly as below:

python tetris_demo.py 1000 --item_max_qty 100. --portion_size 500. --overflow_thresh 0.2 --underflow_thresh 0.1

which should return the result of the algorithm:

------------
RESULT
------------
40 batches for 1 persons (portion of 500.0): 502 items
1 batches for 3 persons (portion of 500.0): 27 items
3 batches for 2 persons (portion of 500.0): 65 items
Average batch loss: 41.91587070338677
Number of remaining items: 201 portioned, 4 unportioned
Number of large items: 201
Number of unindentified items: 0

Many parameters can be adjusted with the previous arguments. To check the full list of arguments and their meaning, use the help of the parser:

python tetris_demo.py -h

Useful links

TODO

  • Implement an EAN - product information function
  • Implement a naive meal balancing algorithm
  • Explore brute force and smart optimisation techniques