Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Food-Recmmendation-System-Python

This is the Recommendation Engine that will be used in building the Lunchbox App, a platform for ordering food and keeping track of user expenditure and canteen sales. Regardless of whether or not this is actually implemented in all the canteens of IIT Kanpur (given the potential for frauds & cyber-attacks) I will still complete the platform.

Also, I would be open-sourcing the app so that any campus can implement a cash-less & integrated system of ordering food across their whole campus. After all, what good are IITs for if our canteens still keep track of student accounts on paper registers!

Build instructions

  • git clone https://github.com/gsunit/Food-Recommendation-System-Pyhton.git
  • Run the Jupyter Notebook src.ipynb

Demographic Filtering

Suggesting the items that are well-received and popular among the users. Most trending items and items with the best rating rise to the top and get shortlisted for recommendation.

importpandasaspdimportnumpyasnp# Importing db of food items across all canteens registered on the platformdf1=pd.read_csv('./db/food.csv')
df1.columns= ['food_id','title','canteen_id','price', 'num_orders', 'category', 'avg_rating', 'num_rating', 'tags']
df1
food_idtitlecanteen_idpricenum_orderscategoryavg_ratingnum_ratingtags
01Lala Maggi13035maggi3.910veg, spicy
12Cheese Maggi12540maggi3.815veg
23Masala Maggi12510maggi3.010veg, spicy
34Veg Maggi13025maggi2.55veg, healthy
45Paneer Tikka16050Punjabi4.630veg, healthy
56Chicken Tikka18040Punjabi4.228nonveg, healthy, spicy

Results of demographic filtering

top_rated_items[['title', 'num_rating', 'avg_rating', 'score']].head()
pop_items[['title', 'num_orders']].head()
titlenum_ratingavg_ratingscore
4Paneer Tikka304.64.288889
5Chicken Tikka284.24.013953
1Cheese Maggi153.83.733333
titlenum_orders
4Paneer Tikka50
1Cheese Maggi40
5Chicken Tikka40
0Lala Maggi35
3Veg Maggi25

Content Based Filtering

A bit more personalised recommendation. We will analyse the past orders of the user and suggest back those items which are similar.

Also, since each person has a "home canteen", the user should be notified of any new items included in the menu by the vendor.

We will be use Count Vectorizer from Scikit-Learn to find similarity between items based on their title, category and tags. To bring all these properties of each item together, we create a "soup" of tags. "Soup" is a processed string correspnding to each item, formed using the constituents of tags, tile and category.

food_idtitlecanteen_idpricenum_orderscategoryavg_ratingnum_ratingtagssoup
01Lala Maggi13035maggi3.910veg, spicyveg spicy lala maggi
12Cheese Maggi12540maggi3.815vegveg cheese maggi
23Masala Maggi12510maggi3.010veg, spicyveg spicy masala maggi

Using CountVectorizer from Scikit-Learn

# Import CountVectorizer and create the count matrixfromsklearn.feature_extraction.textimportCountVectorizercount=CountVectorizer(stop_words='english')
# df1['soup']count_matrix=count.fit_transform(df1['soup'])
# Compute the Cosine Similarity matrix based on the count_matrixfromsklearn.metrics.pairwiseimportcosine_similaritycosine_sim=cosine_similarity(count_matrix, count_matrix)

Sample Recommendation

df1.loc[get_recommendations(title="Paneer Tikka")]
food_idtitlecanteen_idpricenum_orderscategoryavg_ratingnum_ratingtagssoup
56Chicken Tikka18040Punjabi4.228nonveg, healthy, spicynonveg healthy spicy chicken tikka punjabi
34Veg Maggi13025maggi2.55veg, healthyveg healthy maggi

After all the hard work, we finally get the recommendations

personalised_recomms(orders, df1, current_user, columns)
get_new_and_specials_recomms(new_and_specials, users, df1, current_canteen, columns)
get_top_rated_items(top_rated_items, df1, columns)
get_popular_items(pop_items, df1, columns).head(3)
titlecanteen_idpricecomment
0Veg Maggi130based on your past orders
1Paneer Tikka160based on your past orders
2Chicken Tikka180based on your past orders
titlecanteen_idpricecomment
0Cheese Maggi125new/today's special item in your home canteen
titlecanteen_idpricecomment
0Paneer Tikka160top rated items across canteens
1Chicken Tikka180top rated items across canteens
2Cheese Maggi125top rated items across canteens
titlecanteen_idpricecomment
0Paneer Tikka160most popular items across canteens
1Cheese Maggi125most popular items across canteens
2Chicken Tikka180most popular items across canteens

These are just simple algorithms to make personalised & general recommendations to users. We can easily use collaborative filtering or incorporate neural networks to make our prediction even better. However, these are more computationally intensive methods. Kinda overkill, IMO! Let's build that app first, then move on to other features!

Star the repository and send in your PRs if you think the engine needs any improvement or help me implement some more advanced features.

About

Food recommendation system in python

Topics

Resources

Stars

25 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages