Create menu's recommendation based on user's preference and user's customer segmentation by using Neural Collaborative Filtering (NCF) He et al., 2017 and K-Means Clustering . Due to sensitive information in the dataset, the data used in the recommender/cluster model is not stored in this data folder.
Pretrained NCF model available at lightning_logs/menus_df/checkpoints/epoch=49-step=504500.ckpt
using NVIDIA T4 GPU on original data.
Follow these steps to run the API code for generating sales and menus recommendation for particular user:
- Insert the data (csv format) in the data folder
- Install all required packages via terminal
pip install -r requirements.txt
- Run
main.py
to start the flask API
python main.py
- On seperate terminal, input User ID listed in the data and run this,
curl -X POST http://127.0.0.1:80/recms -H 'Content-Type: application/json' -d '{"user_id":"XXXXXXXX"}'
- You can get the sales and menus recommendation in following format,
{'sales_id':['AAA','BBB',...], 'menu_id': ['CCC', 'DDD', ...]}
To train and evaluate NCF model run these steps:
- Insert the data (csv format) in the data folder
- Install all required packages via terminal
pip install -r requirements.txt
- Run
train.py
and specify model parameters with arguments, for example if you want to train the model from beginning:
python train.py --path data/ --device cpu --num_factors 10 --num_hiddens '[10,10,10]' --num_neg 8 --epochs 50 --batch_size 16 --weight_decay 1e-5 --lr 0.01
If you want to use pretrained model, use this format
python train.py --device gpu --checkpoint lightning_logs/menus_df/checkpoints/epoch=49-step=504500.ckpt
All the checkpoints are stored in lightning_logs
folder
- Evaluate model by using this format
python evaluate.py --pretrained lightning_logs/menus_df/checkpoints/epoch=49-step=504500.ckpt
For more detailed information about the analyis and code, you can run the Recommender_System.ipynb
. Here you can find explanation for each steps in developing recommender system and cluster customers. Outputs are not shown because of sensitive information, you may want to include the data in data folder.