├── Important points.docx ├── Diet Recommendation System.pdf ├── Personalized Diet Recommendation System in Healthcare.pptx ├── inputfin.csv ├── README.md ├── input.csv ├── finalgui.py └── gui (1).py /Important points.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frason88/Diet-Recommendation-System-/HEAD/Important points.docx -------------------------------------------------------------------------------- /Diet Recommendation System.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frason88/Diet-Recommendation-System-/HEAD/Diet Recommendation System.pdf -------------------------------------------------------------------------------- /Personalized Diet Recommendation System in Healthcare.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frason88/Diet-Recommendation-System-/HEAD/Personalized Diet Recommendation System in Healthcare.pptx -------------------------------------------------------------------------------- /inputfin.csv: -------------------------------------------------------------------------------- 1 | 0Calories ,1Fats (gm),2Proteins(g),3Iron(mg),4Calcium(mg),5Sodium(mg),6Potassium(mg),7Carbohydrates (gm),8Fibre (gm),9Vitamin D (mcg),10Sugars (gm) 2 | 160,15,2,0.55,12,7,485,8.5,6.7,0,0.7 3 | 89,0.3,1.1,0.26,5,1,358,8.5,2.6,0,12 4 | 349,0.4,14,6.8,190,298,77,8.5,13,0,46 5 | 331,24,20,0.84,497,966,363,8.5,0,0,0 6 | 2,0,0.3,0.02,2,1,50,8.5,0,0,0 7 | 97,1.4,3.3,0.55,2,253,3.3,8.5,2.7,0,7.7 8 | 93,2.1,5.6,2.63,2,9,272,8.5,11,0,6.3 9 | 97,6.9,3.8,0.12,2,52,178,8.5,0,0,0 10 | 553,44,18,6.68,2,12,660,8.5,3.3,0,5.9 11 | 97,0.2,1.5,0.8,2,3,212,8.5,11,0,0 12 | 57,0.1,0.4,0.18,2,1,116,8.5,3.1,0,9.8 13 | 411,17,46,8.57,2,329,1129,8.5,7.1,200,5.7 14 | 381,1.4,2,0.8,2,286,110,8.5,2.5,0,65 15 | 429,9.5,13,2.28,2,490,241,8.5,14,0,0.5 16 | 168,3.7,4.5,8,2,94,76,8.5,0.9,0,0.1 17 | 156,1.7,5,17.2,2,207,63,8.5,2.1,0,0.74 18 | 130,1.5,2.6,3.16,2,201,117,8.5,1.1,0,0.5 19 | 16,0.2,1.2,0.47,2,42,212,8.5,0.9,0,2.63 20 | 60,4,3.1,0.08,2,70,234,8.5,0,1,7 21 | 407,6.2,4.4,3.81,2,457,51,8.5,2.9,0,55 22 | 188,7.2,4.4,24,2,522,91,8.5,2.2,0,0.24 23 | 151,2.4,9,37.4,2,438,180,8.5,1,0,1.35 24 | 579,50,21,3.71,2,1,733,8.5,13,0,4.4 25 | 22,0.3,3.1,0.5,2,5,318,8.5,1,7,2 26 | 196,15,14,1.89,2,207,152,8.5,0,88,0.4 27 | 76,0.1,1.4,0.72,2,27,230,8.5,2.5,0,5.7 28 | 87,0.1,1.9,0.31,2,240,379,8.5,2,0,0.9 29 | 45,0.2,0.7,0.2,2,1,200,8.5,0.2,0,8.4 30 | 73,1.9,10,0.04,2,34,141,8.5,0,0,3.6 31 | 40,0.9,3.2,0.88,2,1,92,8.5,2.6,0,0 32 | 1,0,0.2,0.02,2,1,0.2,8.5,0,0,0 33 | 486,31,17,7.72,2,16,407,8.5,34,0,0 34 | 384,0.9,5.9,19.4,2,571,107,8.5,2.7,286,7.8 35 | 1,0,0,0.08,2,1,9,8.5,0,0,0 36 | 52,0.2,0.3,0.12,2,1,107,8.5,24,0,10 37 | 32,0.3,0.7,0.41,2,1,153,8.5,2,0,4.9 38 | 120,1.9,4.4,1.49,2,7,172,8.5,2.8,0,0.9 39 | 350,22,4.3,0.75,2,313,362,8.5,3.2,0,2.2 40 | 550,50,22,3.4,2,1531,257,8.5,0,0,0 41 | 519,34,2.3,1.25,2,6,536,8.5,7.7,0,35 42 | 304,0,0.3,0.42,2,4,52,8.5,0.2,0,82 43 | 535,30,7.7,2.35,2,79,372,8.5,3.4,0,52 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | A wide variety of ingredients, cultures and personal tastes makes decisions about what to eat a great problem. Many diseases that were previously thought of as hereditary are now seen to be connected to biological dysfunction related to nutrition. Being healthy and eating better is something the vast majority of the population wants and doing so usually requires great effort. 3 | The working prototype accomplishes a Personalized Diet Recommendation System with the integration of Machine Learning Algorithms to recommend the right food at right time and with the right nutrition, calories, fat, etc. 4 | 5 | ## Objective 6 | To establish a working prototype of a Personalized Diet Recommendation System. 7 | 8 | ## How we built it 9 | [Design Architecture](https://ibb.co/8cN8Vtj) 10 | 11 | ## Model Design 12 | [Design Architecture](https://ibb.co/W2qzn6p) 13 | 14 | ## Challenges we ran into 15 | The issue that is being faced by the current working model is it does not facilitate a user with the food classification based on the food timings on a daily basis other than general food timings. 16 | The existing system struggles to provide a weight gain/loss scheme to a user based on his long-term food habits. 17 | 18 | ## Accomplishments that we're proud of 19 | I learned a lot of different Machine Learning algorithms along with how to build a Recommendation System. 20 | 21 | ## Results 22 | A working prototype of a Diet Recommendation System is established. 23 | The module works on the basis of K-Means Clustering and Random Forest Classification Algorithms. 24 | Tkinter-based GUI is implemented. 25 | 26 | ## What we learned 27 | - Tkinter 28 | - Recommendation System 29 | - Random Forest 30 | - K-Mean Clustering 31 | 32 | ## What's next for Diet Recommendation System in Healthcare using ML Approaches 33 | The module can be implemented as a cloud-based application. 34 | Packaged as a single entity, ready for production environment deployment. 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /input.csv: -------------------------------------------------------------------------------- 1 | Food_items,Breakfast,Lunch,Dinner,VegNovVeg,Calories,Fats,Proteins,Iron,Calcium,Sodium,Potassium,Carbohydrates,Fibre,VitaminD,Sugars 2 | Asparagus Cooked,0,1,1, ,22,0.2,2.4,0.91,23,14,224,4.1,2,0,1.3 3 | Avocados,1,0,0,0,160,15,2,0.55,12,7,485,8.5,6.7,0,0.7 4 | Bananas,1,0,0,0,89,0.3,1.1,0.26,5,1,358,23,2.6,0,12 5 | Bagels made in wheat,0,1,1,0,250,1.5,10,2.76,20,439,165,49,4.1,0,6.1 6 | Berries,1,0,0,0,349,0.4,14,6.8,190,298,77,77,13,0,46 7 | Brocolli,0,1,1,0,25,0.5,3.8,1.27,118,56,343,3.1,2.8,0,0.6 8 | Brown Rice,0,1,1,0,362,2.7,7.5,1.8,33,4,268,76,3.4,0,0 9 | Cauliflower,0,1,1,0,32,0.3,3,0.72,32,259,278,6.3,3.3,0,0 10 | American cheese,1,0,0,0,331,24,20,0.84,497,966,363,8.3,0,0,0 11 | Coffee,1,0,0,0,2,0,0.3,0.02,2,1,50,0.2,0,0,0 12 | Corn,1,1,1,0,97,1.4,3.3,0.55,2,253,3.3,22,2.7,0,7.7 13 | Dark chocolates,0,0,1,0,556,32,5.5,2.13,30,6,502,60,6.5,0,48 14 | Grapes,1,0,0,0,93,2.1,5.6,2.63,363,9,272,17,11,0,6.3 15 | Milk,1,0,1,0,97,6.9,3.8,0.12,169,52,178,5.2,0,0,0 16 | Cashew Nuts,1,0,0,0,553,44,18,6.68,37,12,660,30,3.3,0,5.9 17 | Onions,0,1,1,0,40,0.1,1.1,0.21,23,4,146,9.3,1.7,0,4.2 18 | Orange,1,0,0,0,97,0.2,1.5,0.8,161,3,212,25,11,0,0 19 | Pasta canned with tomato sauce,0,1,1,0,71,0.7,2.2,0.91,13,381,192,14,0.9,0,4 20 | Pears,1,0,0,0,57,0.1,0.4,0.18,9,1,116,15,3.1,0,9.8 21 | Peas,0,1,1,0,81,0.4,5.4,1.47,25,5,244,14,5.7,0,5.7 22 | Protein Powder,1,0,0,0,411,17,46,8.57,500,329,1129,19,7.1,200,5.7 23 | Pumpkin,0,1,1,0,18,0.1,0.7,0.57,15,237,230,4.3,1.1,0,2.1 24 | Tuna Salad,0,1,1,1,187,9.3,16,1,17,402,178,9.4,0,0,0 25 | Tuna Fish,0,0,1,1,184,6.3,30,1.31,10,50,323,0,0,0,0 26 | Peproni Pizza,0,0,1,0,298,14,12,2.14,146,692,199,30,1.8,0,3.2 27 | Cheese Pizza,0,0,1,0,276,11,11,2.47,192,580,170,33,2.1,0,2.5 28 | French Fries,0,1,1,0,289,14,3.5,0.91,17,357,545,37,3.9,0,0.3 29 | Chicken Burger,0,1,1,1,292,15,18,0.62,13,859,315,20,1.3,0,0 30 | Cheese Burger,0,1,1,0,256,12,13,2.78,92,660,178,25,1.4,0,0 31 | Chicken Sandwich,0,1,1,1,257,12,15,1.32,92,605,256,23,1.2,0,5 32 | Sugar Doughnuts,0,1,1,0,426,23,5.2,1.06,60,402,102,51,1.5,0,32 33 | Chocolate Doughnuts,0,1,1,0,452,25,4.9,4,24,326,201,51,1.9,0,27 34 | Pop Corn - Caramel,1,0,1,0,381,1.4,2,0.8,18,286,110,90,2.5,0,65 35 | Pop Corn,1,0,1,0,429,9.5,13,2.28,11,490,241,73,14,0,0.5 36 | Dosa,1,1,1,0,168,3.7,4.5,8,0.7,94,76,29,0.9,0,0.1 37 | Idli,1,1,1,0,156,1.7,5,17.2,4,207,63,30.2,2.1,0,0.74 38 | Poha,1,0,0,0,130,1.5,2.6,3.16,1,201,117,26.9,1.1,0,0.5 39 | Chappati,0,1,1,0,297,7.5,11,3.01,93,409,266,46,4.9,0,2.7 40 | Tomato,1,1,1,0,16,0.2,1.2,0.47,5,42,212,3.2,0.9,0,2.63 41 | Yogurt,1,1,1,0,60,4,3.1,0.08,183,70,234,7,0,1,7 42 | Brownie,1,0,0,0,407,6.2,4.4,3.81,17,457,51,84,2.9,0,55 43 | Noodles,0,1,1,0,108,0.2,1.8,0.14,4,19,4,24,1,0,0 44 | Uttapam,1,1,1,0,188,7.2,4.4,24,6.4,522,91,26.4,2.2,0,0.24 45 | Bhaji Pav,1,0,0,0,151,2.4,9,37.4,3.4,438,180,29.3,1,0,1.35 46 | Dal Makhani,0,1,1,0,109,8.5,2.1,35.2,8.3,243,366,6.3,1.5,0,3.29 47 | Almonds,1,0,0,0,579,50,21,3.71,269,1,733,22,13,0,4.4 48 | Mushrooms,1,1,1,0,22,0.3,3.1,0.5,3,5,318,3.3,1,7,2 49 | Egg Yolk cooked,1,0,0,1,196,15,14,1.89,62,207,152,0.8,0,88,0.4 50 | Sweet Potatoes cooked,1,1,0,0,76,0.1,1.4,0.72,27,27,230,18,2.5,0,5.7 51 | Boiled Potatoes,1,1,1,0,87,0.1,1.9,0.31,5,240,379,20,2,0,0.9 52 | White Rice,0,1,1,0,360,0.6,6.6,4.36,9,1,86,79,1.4,0,0 53 | Orange juice,1,0,0,0,45,0.2,0.7,0.2,11,1,200,10,0.2,0,8.4 54 | Greek yogurt plain,1,1,1,0,73,1.9,10,0.04,115,34,141,3.9,0,0,3.6 55 | Oat Bran Cooked,1,0,0,0,40,0.9,3.2,0.88,10,1,92,11,2.6,0,0 56 | Green Tea,1,0,0,0,1,0,0.2,0.02,0,1,0.2,0,0,0,0 57 | Chia seeds,1,0,0,0,486,31,17,7.72,631,16,407,42,34,0,0 58 | Cottage cheese with vegetables,0,1,1,0,95,4.2,11,0.1,56,403,86,3,0.1,0,0.4 59 | Salmon,0,1,1,1,127,4.4,21,0.38,7,75,366,0,0,435,0 60 | Cereals-Corn Flakes,1,0,0,0,384,0.9,5.9,19.4,2,571,107,88,2.7,286,7.8 61 | Beans,0,1,1,0,31,0.2,1.8,1.03,37,6,211,7,2.7,0,3.3 62 | Lentils,0,1,1,0,101,0.5,8.8,3.1,14,246,284,21,0,0,0 63 | Pasta with corn homemade,0,1,1,0,126,0.7,2.6,0.25,1,0,31,28,4.8,0,0 64 | Tea,1,0,0,0,1,0,0,0.08,2,1,9,0.2,0,0,0 65 | Apples,1,0,0,0,52,0.2,0.3,0.12,6,1,107,14,24,0,10 66 | Strawberries,1,0,0,0,32,0.3,0.7,0.41,16,1,153,7.7,2,0,4.9 67 | Quninoa,1,1,0,0,120,1.9,4.4,1.49,17,7,172,21,2.8,0,0.9 68 | Goat meat,0,1,1,1,109,2.3,21,2.83,13,82,385,57,0,0,0 69 | Rabbit meat,0,1,1,1,114,2.3,22,3.2,12,50,378,0,0,0,0 70 | Chicken Strips,0,0,1,1,295,15,19,0.72,11,798,334,22,1.1,0,0.3 71 | Steak Fries,0,1,1,1,255,13,3.3,0.69,19,43,551,31,3.5,0,0.9 72 | Mexican Rice,0,1,1,0,195,4.9,3.6,1.18,39,677,131,34,1.1,0,1.4 73 | Fried Shrimp,0,0,1,1,319,20,14,1.54,47,1400,128,21,1.5,0,0.8 74 | Spaghetti and meatballs,0,0,1,1,170,8.5,7.8,1.29,45,351,206,16,1.5,0,2 75 | Macroni n Cheese ,0,1,1,0,194,12,6.5,57,145,375,127,16,1.1,0,2.8 76 | Pork cooked,0,0,1,1,297,21,26,1.29,22,73,362,0,0,0,0 77 | Bacon cooked,0,0,1,1,146,2.8,28,0.56,7,993,999,1.8,0,0,1.2 78 | Nachos,1,1,1,0,350,22,4.3,0.75,63,313,362,35,3.2,0,2.2 79 | Chicken Popcorn,0,1,1,1,351,22,18,1.42,32,1140,288,21,1,0,0 80 | Turkey cooked,0,1,1,1,203,10,27,1.52,28,78,294,0,0,8,0 81 | Oyster cooked,0,1,1,1,159,4,29,4.9,6,81,409,0,0,0,0 82 | Beef sticks,1,0,0,1,550,50,22,3.4,68,1531,257,5.4,0,0,0 83 | Banana Chips,1,0,0,0,519,34,2.3,1.25,18,6,536,58,7.7,0,35 84 | Honey,1,0,1,0,304,0,0.3,0.42,6,4,52,82,0.2,0,82 85 | Chocolate Icecream,0,0,1,0,216,11,3.8,0.93,109,76,249,28,1.2,0,25 86 | Vanilla Ice cream,0,0,1,0,207,11,3.5,0.09,128,80,199,24,0.7,0,21 87 | Strawberry Icecream,0,0,1,0,192,8.4,3.2,0.21,120,60,188,28,0.9,0,0 88 | Marshmallows,0,0,1,0,318,0.2,1.8,0.23,3,80,5,81,0.1,0,58 89 | Chocolate milk,1,0,0,0,535,30,7.7,2.35,189,79,372,59,3.4,0,52 90 | Rice Pudding,0,0,1,0,376,0.1,2.7,1.79,14,366,5,91,0.7,0,0 91 | -------------------------------------------------------------------------------- /finalgui.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import simpledialog 3 | main_win = Tk() 4 | 5 | def Weight_Loss(): 6 | print(" Age : %s Years \n Weight: %s Kg \n Hight: %s m \n" % (e1.get(), e3.get(), e4.get())) 7 | 8 | import pandas as pd 9 | import numpy as np 10 | from sklearn.cluster import KMeans 11 | import tkinter as tk 12 | 13 | 14 | ROOT = tk.Tk() 15 | 16 | ROOT.withdraw() 17 | 18 | USER_INP = simpledialog.askstring(title="Food Timing", 19 | prompt="Enter 1 for Breakfast, 2 for Lunch and 3 for Dinner") 20 | 21 | 22 | data=pd.read_csv('input.csv') 23 | 24 | 25 | Breakfastdata=data['Breakfast'] 26 | BreakfastdataNumpy=Breakfastdata.to_numpy() 27 | 28 | Lunchdata=data['Lunch'] 29 | LunchdataNumpy=Lunchdata.to_numpy() 30 | 31 | Dinnerdata=data['Dinner'] 32 | DinnerdataNumpy=Dinnerdata.to_numpy() 33 | 34 | Food_itemsdata=data['Food_items'] 35 | breakfastfoodseparated=[] 36 | Lunchfoodseparated=[] 37 | Dinnerfoodseparated=[] 38 | 39 | breakfastfoodseparatedID=[] 40 | LunchfoodseparatedID=[] 41 | DinnerfoodseparatedID=[] 42 | 43 | for i in range(len(Breakfastdata)): 44 | if BreakfastdataNumpy[i]==1: 45 | breakfastfoodseparated.append(Food_itemsdata[i]) 46 | breakfastfoodseparatedID.append(i) 47 | if LunchdataNumpy[i]==1: 48 | Lunchfoodseparated.append(Food_itemsdata[i]) 49 | LunchfoodseparatedID.append(i) 50 | if DinnerdataNumpy[i]==1: 51 | Dinnerfoodseparated.append(Food_itemsdata[i]) 52 | DinnerfoodseparatedID.append(i) 53 | 54 | 55 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 56 | LunchfoodseparatedIDdata = LunchfoodseparatedIDdata.T 57 | val=list(np.arange(5,16)) 58 | Valapnd=[0]+[4]+val 59 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 60 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 61 | 62 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 63 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 64 | val=list(np.arange(5,16)) 65 | Valapnd=[0]+[4]+val 66 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 67 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 68 | 69 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 70 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 71 | val=list(np.arange(5,16)) 72 | Valapnd=[0]+[4]+val 73 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 74 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 75 | 76 | age=int(e1.get()) 77 | weight=float(e3.get()) 78 | height=float(e4.get()) 79 | bmi = weight/(height**2) 80 | 81 | for lp in range (0,80,20): 82 | test_list=np.arange(lp,lp+20) 83 | for i in test_list: 84 | if(i == age): 85 | print('age is between',str(lp),str(lp+10)) 86 | agecl=round(lp/20) 87 | 88 | print("Your body mass index is: ", bmi) 89 | if ( bmi < 16): 90 | print("severely underweight") 91 | clbmi=4 92 | elif ( bmi >= 16 and bmi < 18.5): 93 | print("underweight") 94 | clbmi=3 95 | elif ( bmi >= 18.5 and bmi < 25): 96 | print("Healthy") 97 | clbmi=2 98 | elif ( bmi >= 25 and bmi < 30): 99 | print("overweight") 100 | clbmi=1 101 | elif ( bmi >=30): 102 | print("severely overweight") 103 | clbmi=0 104 | 105 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 106 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 107 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 108 | ti=(clbmi+agecl)/2 109 | 110 | ## K-Means Based Dinner Food 111 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 112 | X = np.array(Datacalorie) 113 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 114 | XValu=np.arange(0,len(kmeans.labels_)) 115 | dnrlbl=kmeans.labels_ 116 | 117 | ## K-Means Based Lunch Food 118 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 119 | X = np.array(Datacalorie) 120 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 121 | XValu=np.arange(0,len(kmeans.labels_)) 122 | lnchlbl=kmeans.labels_ 123 | 124 | ## K-Means Based Breakfast Food 125 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 126 | X = np.array(Datacalorie) 127 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 128 | XValu=np.arange(0,len(kmeans.labels_)) 129 | brklbl=kmeans.labels_ 130 | 131 | ## Reading of the Dataset 132 | datafin=pd.read_csv('inputfin.csv') 133 | 134 | dataTog=datafin.T 135 | 136 | bmicls=[0,1,2,3,4] 137 | agecls=[0,1,2,3,4] 138 | 139 | weightlosscat = dataTog.iloc[[1,2,7,8]] 140 | weightlosscat=weightlosscat.T 141 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 142 | weightgaincat=weightgaincat.T 143 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 144 | healthycat=healthycat.T 145 | weightlosscatDdata=weightlosscat.to_numpy() 146 | weightgaincatDdata=weightgaincat.to_numpy() 147 | healthycatDdata=healthycat.to_numpy() 148 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 149 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 150 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 151 | 152 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 153 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 154 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 155 | 156 | t=0 157 | r=0 158 | s=0 159 | yt=[] 160 | yr=[] 161 | ys=[] 162 | for zz in range(5): 163 | for jj in range(len(weightlosscat)): 164 | valloc=list(weightlosscat[jj]) 165 | valloc.append(bmicls[zz]) 166 | valloc.append(agecls[zz]) 167 | weightlossfin[t]=np.array(valloc) 168 | yt.append(brklbl[jj]) 169 | t+=1 170 | 171 | for jj in range(len(weightlosscat)): 172 | valloc=list(weightlosscat[jj]) 173 | valloc.append(bmicls[zz]) 174 | valloc.append(agecls[zz]) 175 | weightlossfin[r]=np.array(valloc) 176 | yr.append(lnchlbl[jj]) 177 | r+=1 178 | 179 | for jj in range(len(weightlosscat)): 180 | valloc=list(weightlosscat[jj]) 181 | valloc.append(bmicls[zz]) 182 | valloc.append(agecls[zz]) 183 | weightlossfin[s]=np.array(valloc) 184 | ys.append(dnrlbl[jj]) 185 | s+=1 186 | 187 | X_test=np.zeros((len(weightlosscat),6),dtype=np.float32) 188 | 189 | for jj in range(len(weightlosscat)): 190 | valloc=list(weightlosscat[jj]) 191 | valloc.append(agecl) 192 | valloc.append(clbmi) 193 | X_test[jj]=np.array(valloc)*ti 194 | 195 | 196 | from sklearn.model_selection import train_test_split 197 | 198 | val=int(USER_INP) 199 | 200 | if val==1: 201 | X_train= weightlossfin 202 | y_train=yt 203 | 204 | elif val==2: 205 | X_train= weightlossfin 206 | y_train=yr 207 | 208 | elif val==3: 209 | X_train= weightlossfin 210 | y_train=ys 211 | 212 | from sklearn.ensemble import RandomForestClassifier 213 | 214 | clf=RandomForestClassifier(n_estimators=100) 215 | 216 | clf.fit(X_train,y_train) 217 | 218 | y_pred=clf.predict(X_test) 219 | 220 | 221 | print ('SUGGESTED FOOD ITEMS ::') 222 | for ii in range(len(y_pred)): 223 | if y_pred[ii]==2: 224 | print (Food_itemsdata[ii]) 225 | 226 | 227 | def Weight_Gain(): 228 | print(" Age: %s\n Weight%s\n Hight%s\n" % (e1.get(), e3.get(), e4.get())) 229 | 230 | 231 | import pandas as pd 232 | import numpy as np 233 | from sklearn.cluster import KMeans 234 | import tkinter as tk 235 | 236 | ROOT = tk.Tk() 237 | 238 | ROOT.withdraw() 239 | 240 | USER_INP = simpledialog.askstring(title="Food Timing", 241 | prompt="Enter 1 for Breakfast, 2 for Lunch and 3 for Dinner") 242 | 243 | data=pd.read_csv('input.csv') 244 | data.head(5) 245 | Breakfastdata=data['Breakfast'] 246 | BreakfastdataNumpy=Breakfastdata.to_numpy() 247 | 248 | Lunchdata=data['Lunch'] 249 | LunchdataNumpy=Lunchdata.to_numpy() 250 | 251 | Dinnerdata=data['Dinner'] 252 | DinnerdataNumpy=Dinnerdata.to_numpy() 253 | 254 | Food_itemsdata=data['Food_items'] 255 | breakfastfoodseparated=[] 256 | Lunchfoodseparated=[] 257 | Dinnerfoodseparated=[] 258 | 259 | breakfastfoodseparatedID=[] 260 | LunchfoodseparatedID=[] 261 | DinnerfoodseparatedID=[] 262 | 263 | for i in range(len(Breakfastdata)): 264 | if BreakfastdataNumpy[i]==1: 265 | breakfastfoodseparated.append(Food_itemsdata[i]) 266 | breakfastfoodseparatedID.append(i) 267 | if LunchdataNumpy[i]==1: 268 | Lunchfoodseparated.append(Food_itemsdata[i]) 269 | LunchfoodseparatedID.append(i) 270 | if DinnerdataNumpy[i]==1: 271 | Dinnerfoodseparated.append(Food_itemsdata[i]) 272 | DinnerfoodseparatedID.append(i) 273 | 274 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 275 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 276 | val=list(np.arange(5,15)) 277 | Valapnd=[0]+val 278 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 279 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 280 | 281 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 282 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 283 | val=list(np.arange(5,15)) 284 | Valapnd=[0]+val 285 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 286 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 287 | 288 | 289 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 290 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 291 | val=list(np.arange(5,15)) 292 | Valapnd=[0]+val 293 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 294 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 295 | 296 | age=int(e1.get()) 297 | weight=float(e3.get()) 298 | height=float(e4.get()) 299 | bmi = weight/(height**2) 300 | agewiseinp=0 301 | 302 | for lp in range (0,80,20): 303 | test_list=np.arange(lp,lp+20) 304 | for i in test_list: 305 | if(i == age): 306 | print('age is between',str(lp),str(lp+10)) 307 | tr=round(lp/20) 308 | agecl=round(lp/20) 309 | 310 | print("Your body mass index is: ", bmi) 311 | if ( bmi < 16): 312 | print("severely underweight") 313 | clbmi=4 314 | elif ( bmi >= 16 and bmi < 18.5): 315 | print("underweight") 316 | clbmi=3 317 | elif ( bmi >= 18.5 and bmi < 25): 318 | print("Healthy") 319 | clbmi=2 320 | elif ( bmi >= 25 and bmi < 30): 321 | print("overweight") 322 | clbmi=1 323 | elif ( bmi >=30): 324 | print("severely overweight") 325 | clbmi=0 326 | val1=DinnerfoodseparatedIDdata.describe() 327 | valTog=val1.T 328 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 329 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 330 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 331 | ti=(bmi+agecl)/2 332 | 333 | ## K-Means Based Dinner Food 334 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 335 | X = np.array(Datacalorie) 336 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 337 | XValu=np.arange(0,len(kmeans.labels_)) 338 | dnrlbl=kmeans.labels_ 339 | 340 | ## K-Means Based lunch Food 341 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 342 | X = np.array(Datacalorie) 343 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 344 | XValu=np.arange(0,len(kmeans.labels_)) 345 | lnchlbl=kmeans.labels_ 346 | 347 | ## K-Means Based lunch Food 348 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 349 | X = np.array(Datacalorie) 350 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 351 | XValu=np.arange(0,len(kmeans.labels_)) 352 | brklbl=kmeans.labels_ 353 | 354 | inp=[] 355 | datafin=pd.read_csv('inputfin.csv') 356 | datafin.head(5) 357 | dataTog=datafin.T 358 | bmicls=[0,1,2,3,4] 359 | agecls=[0,1,2,3,4] 360 | weightlosscat = dataTog.iloc[[1,2,7,8]] 361 | weightlosscat=weightlosscat.T 362 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 363 | weightgaincat=weightgaincat.T 364 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 365 | healthycat=healthycat.T 366 | weightlosscatDdata=weightlosscat.to_numpy() 367 | weightgaincatDdata=weightgaincat.to_numpy() 368 | healthycatDdata=healthycat.to_numpy() 369 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 370 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 371 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 372 | 373 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 374 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 375 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 376 | t=0 377 | r=0 378 | s=0 379 | yt=[] 380 | yr=[] 381 | ys=[] 382 | for zz in range(5): 383 | for jj in range(len(weightgaincat)): 384 | valloc=list(weightgaincat[jj]) 385 | valloc.append(bmicls[zz]) 386 | valloc.append(agecls[zz]) 387 | weightgainfin[t]=np.array(valloc) 388 | yt.append(brklbl[jj]) 389 | t+=1 390 | for jj in range(len(weightgaincat)): 391 | valloc=list(weightgaincat[jj]) 392 | valloc.append(bmicls[zz]) 393 | valloc.append(agecls[zz]) 394 | weightgainfin[r]=np.array(valloc) 395 | yr.append(lnchlbl[jj]) 396 | r+=1 397 | for jj in range(len(weightgaincat)): 398 | valloc=list(weightgaincat[jj]) 399 | valloc.append(bmicls[zz]) 400 | valloc.append(agecls[zz]) 401 | weightgainfin[s]=np.array(valloc) 402 | ys.append(dnrlbl[jj]) 403 | s+=1 404 | 405 | 406 | X_test=np.zeros((len(weightgaincat),10),dtype=np.float32) 407 | 408 | 409 | for jj in range(len(weightgaincat)): 410 | valloc=list(weightgaincat[jj]) 411 | valloc.append(agecl) 412 | valloc.append(clbmi) 413 | X_test[jj]=np.array(valloc)*ti 414 | 415 | from sklearn.model_selection import train_test_split 416 | 417 | val=int(USER_INP) 418 | 419 | if val==1: 420 | X_train= weightgainfin 421 | y_train=yt 422 | 423 | elif val==2: 424 | X_train= weightgainfin 425 | y_train=yr 426 | 427 | elif val==3: 428 | X_train= weightgainfin 429 | y_train=ys 430 | 431 | 432 | from sklearn.model_selection import train_test_split 433 | 434 | 435 | from sklearn.ensemble import RandomForestClassifier 436 | 437 | clf=RandomForestClassifier(n_estimators=100) 438 | 439 | clf.fit(X_train,y_train) 440 | 441 | y_pred=clf.predict(X_test) 442 | 443 | 444 | 445 | 446 | print ('SUGGESTED FOOD ITEMS ::') 447 | for ii in range(len(y_pred)): 448 | if y_pred[ii]==2: 449 | print (Food_itemsdata[ii]) 450 | 451 | 452 | 453 | def Healthy(): 454 | print(" Age: %s\n Weight%s\n Hight%s\n" % (e1.get(), e3.get(), e4.get())) 455 | import pandas as pd 456 | import numpy as np 457 | 458 | from sklearn.cluster import KMeans 459 | import tkinter as tk 460 | 461 | ROOT = tk.Tk() 462 | 463 | ROOT.withdraw() 464 | 465 | USER_INP = simpledialog.askstring(title="Food Timing", 466 | prompt="Enter 1 for Breakfast, 2 for Lunch and 3 for Dinner") 467 | 468 | 469 | data=pd.read_csv('input.csv') 470 | data.head(5) 471 | Breakfastdata=data['Breakfast'] 472 | BreakfastdataNumpy=Breakfastdata.to_numpy() 473 | 474 | Lunchdata=data['Lunch'] 475 | LunchdataNumpy=Lunchdata.to_numpy() 476 | 477 | Dinnerdata=data['Dinner'] 478 | DinnerdataNumpy=Dinnerdata.to_numpy() 479 | 480 | Food_itemsdata=data['Food_items'] 481 | breakfastfoodseparated=[] 482 | Lunchfoodseparated=[] 483 | Dinnerfoodseparated=[] 484 | 485 | breakfastfoodseparatedID=[] 486 | LunchfoodseparatedID=[] 487 | DinnerfoodseparatedID=[] 488 | 489 | for i in range(len(Breakfastdata)): 490 | if BreakfastdataNumpy[i]==1: 491 | breakfastfoodseparated.append(Food_itemsdata[i]) 492 | breakfastfoodseparatedID.append(i) 493 | if LunchdataNumpy[i]==1: 494 | Lunchfoodseparated.append(Food_itemsdata[i]) 495 | LunchfoodseparatedID.append(i) 496 | if DinnerdataNumpy[i]==1: 497 | Dinnerfoodseparated.append(Food_itemsdata[i]) 498 | DinnerfoodseparatedID.append(i) 499 | 500 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 501 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 502 | val=list(np.arange(5,15)) 503 | Valapnd=[0]+val 504 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 505 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 506 | 507 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 508 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 509 | val=list(np.arange(5,15)) 510 | Valapnd=[0]+val 511 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 512 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 513 | 514 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 515 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 516 | val=list(np.arange(5,15)) 517 | Valapnd=[0]+val 518 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 519 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 520 | 521 | age=int(e1.get()) 522 | weight=float(e3.get()) 523 | height=float(e4.get()) 524 | bmi = weight/(height**2) 525 | agewiseinp=0 526 | 527 | for lp in range (0,80,20): 528 | test_list=np.arange(lp,lp+20) 529 | for i in test_list: 530 | if(i == age): 531 | print('age is between',str(lp),str(lp+10)) 532 | tr=round(lp/20) 533 | agecl=round(lp/20) 534 | 535 | print("Your body mass index is: ", bmi) 536 | if ( bmi < 16): 537 | print("severely underweight") 538 | clbmi=4 539 | elif ( bmi >= 16 and bmi < 18.5): 540 | print("underweight") 541 | clbmi=3 542 | elif ( bmi >= 18.5 and bmi < 25): 543 | print("Healthy") 544 | clbmi=2 545 | elif ( bmi >= 25 and bmi < 30): 546 | print("overweight") 547 | clbmi=1 548 | elif ( bmi >=30): 549 | print("severely overweight") 550 | clbmi=0 551 | val1=DinnerfoodseparatedIDdata.describe() 552 | valTog=val1.T 553 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 554 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 555 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 556 | ti=(bmi+agecl)/2 557 | 558 | ## K-Means Based Dinner Food 559 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 560 | X = np.array(Datacalorie) 561 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 562 | XValu=np.arange(0,len(kmeans.labels_)) 563 | dnrlbl=kmeans.labels_ 564 | 565 | ## K-Means Based lunch Food 566 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 567 | X = np.array(Datacalorie) 568 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 569 | XValu=np.arange(0,len(kmeans.labels_)) 570 | lnchlbl=kmeans.labels_ 571 | 572 | ## K-Means Based lunch Food 573 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 574 | X = np.array(Datacalorie) 575 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 576 | XValu=np.arange(0,len(kmeans.labels_)) 577 | brklbl=kmeans.labels_ 578 | inp=[] 579 | datafin=pd.read_csv('inputfin.csv') 580 | datafin.head(5) 581 | dataTog=datafin.T 582 | bmicls=[0,1,2,3,4] 583 | agecls=[0,1,2,3,4] 584 | weightlosscat = dataTog.iloc[[1,2,7,8]] 585 | weightlosscat=weightlosscat.T 586 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 587 | weightgaincat=weightgaincat.T 588 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 589 | healthycat=healthycat.T 590 | weightlosscatDdata=weightlosscat.to_numpy() 591 | weightgaincatDdata=weightgaincat.to_numpy() 592 | healthycatDdata=healthycat.to_numpy() 593 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 594 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 595 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 596 | 597 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 598 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 599 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 600 | t=0 601 | r=0 602 | s=0 603 | yt=[] 604 | yr=[] 605 | ys=[] 606 | for zz in range(5): 607 | for jj in range(len(healthycat)): 608 | valloc=list(healthycat[jj]) 609 | valloc.append(bmicls[zz]) 610 | valloc.append(agecls[zz]) 611 | healthycatfin[t]=np.array(valloc) 612 | yt.append(brklbl[jj]) 613 | t+=1 614 | for jj in range(len(healthycat)): 615 | valloc=list(healthycat[jj]) 616 | valloc.append(bmicls[zz]) 617 | valloc.append(agecls[zz]) 618 | healthycatfin[r]=np.array(valloc) 619 | yr.append(lnchlbl[jj]) 620 | r+=1 621 | for jj in range(len(healthycat)): 622 | valloc=list(healthycat[jj]) 623 | valloc.append(bmicls[zz]) 624 | valloc.append(agecls[zz]) 625 | healthycatfin[s]=np.array(valloc) 626 | ys.append(dnrlbl[jj]) 627 | s+=1 628 | 629 | X_test=np.zeros((len(healthycat)*5,9),dtype=np.float32) 630 | for jj in range(len(healthycat)): 631 | valloc=list(healthycat[jj]) 632 | valloc.append(agecl) 633 | valloc.append(clbmi) 634 | X_test[jj]=np.array(valloc)*ti 635 | 636 | 637 | from sklearn.model_selection import train_test_split 638 | 639 | 640 | val=int(USER_INP) 641 | 642 | if val==1: 643 | X_train= healthycatfin 644 | y_train=yt 645 | 646 | elif val==2: 647 | X_train= healthycatfin 648 | y_train=yt 649 | 650 | elif val==3: 651 | X_train= healthycatfin 652 | y_train=ys 653 | 654 | 655 | from sklearn.model_selection import train_test_split 656 | 657 | 658 | from sklearn.ensemble import RandomForestClassifier 659 | 660 | clf=RandomForestClassifier(n_estimators=100) 661 | 662 | clf.fit(X_train,y_train) 663 | 664 | y_pred=clf.predict(X_test) 665 | 666 | print ('SUGGESTED FOOD ITEMS ::') 667 | for ii in range(len(y_pred)): 668 | if y_pred[ii]==2: 669 | print (Food_itemsdata[ii]) 670 | 671 | Label(main_win,text="Age",font='Helvetica 12 bold').grid(row=1,column=0,sticky=W,pady=4) 672 | Label(main_win,text="Weight",font='Helvetica 12 bold').grid(row=2,column=0,sticky=W,pady=4) 673 | Label(main_win,text="Height", font='Helvetica 12 bold').grid(row=3,column=0,sticky=W,pady=4) 674 | 675 | e1 = Entry(main_win,bg="light grey") 676 | e3 = Entry(main_win,bg="light grey") 677 | e4 = Entry(main_win,bg="light grey") 678 | e1.focus_force() 679 | 680 | e1.grid(row=1, column=1) 681 | e3.grid(row=2, column=1) 682 | e4.grid(row=3, column=1) 683 | 684 | 685 | Button(main_win,text='Quit',font='Helvetica 8 bold',command=main_win.quit).grid(row=5,column=0,sticky=W,pady=4) 686 | Button(main_win,text='Weight Loss',font='Helvetica 8 bold',command=Weight_Loss).grid(row=1,column=4,sticky=W,pady=4) 687 | Button(main_win,text='Weight Gain',font='Helvetica 8 bold',command=Weight_Gain).grid(row=2,column=4,sticky=W,pady=4) 688 | Button(main_win,text='Healthy',font='Helvetica 8 bold',command=Healthy).grid(row=3,column=4,sticky=W,pady=4) 689 | main_win.geometry("400x200") 690 | main_win.wm_title("DIET RECOMMENDATION SYSTEM") 691 | main_win.mainloop() 692 | -------------------------------------------------------------------------------- /gui (1).py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from PIL import ImageFilter,Image 3 | from tkinter import filedialog, messagebox 4 | import os 5 | import psutil 6 | import time 7 | import subprocess 8 | import cv2 9 | import fnmatch 10 | 11 | 12 | main_win = Tk() 13 | # main_win.iconbitmap('3/favicon.ico') 14 | 15 | 16 | def show_entry_fields(): 17 | print(" Age: %s\n Veg-NonVeg:%s\n Weight%s\n Hight%s\n" % (e1.get(), e2.get(),e3.get(), e4.get())) 18 | 19 | 20 | def Weight_Loss(): 21 | print(" Age: %s\n Veg-NonVeg:%s\n Weight%s\n Hight%s\n" % (e1.get(), e2.get(),e3.get(), e4.get())) 22 | #!/usr/bin/env python 23 | # coding: utf-8 24 | import pandas as pd 25 | import numpy as np 26 | import os 27 | 28 | import seaborn as sns 29 | import matplotlib.pyplot as plt 30 | from sklearn.cluster import KMeans 31 | import numpy as np 32 | # # New Section 33 | 34 | # In[44]: 35 | 36 | ## Reading of the Dataet 37 | data=pd.read_csv('input.csv') 38 | data.head(5) 39 | 40 | 41 | 42 | # In[46]: 43 | 44 | 45 | Breakfastdata=data['Breakfast'] 46 | BreakfastdataNumpy=Breakfastdata.to_numpy() 47 | 48 | Lunchdata=data['Lunch'] 49 | LunchdataNumpy=Lunchdata.to_numpy() 50 | 51 | Dinnerdata=data['Dinner'] 52 | DinnerdataNumpy=Dinnerdata.to_numpy() 53 | 54 | Food_itemsdata=data['Food_items'] 55 | breakfastfoodseparated=[] 56 | Lunchfoodseparated=[] 57 | Dinnerfoodseparated=[] 58 | 59 | breakfastfoodseparatedID=[] 60 | LunchfoodseparatedID=[] 61 | DinnerfoodseparatedID=[] 62 | 63 | for i in range(len(Breakfastdata)): 64 | if BreakfastdataNumpy[i]==1: 65 | breakfastfoodseparated.append(Food_itemsdata[i]) 66 | breakfastfoodseparatedID.append(i) 67 | if LunchdataNumpy[i]==1: 68 | Lunchfoodseparated.append(Food_itemsdata[i]) 69 | LunchfoodseparatedID.append(i) 70 | if DinnerdataNumpy[i]==1: 71 | Dinnerfoodseparated.append(Food_itemsdata[i]) 72 | DinnerfoodseparatedID.append(i) 73 | 74 | #print ('BREAKFAST FOOD ITEMS') 75 | #print (breakfastfoodseparated) 76 | #print ('LUNCH FOOD ITEMS') 77 | #print (Lunchfoodseparated) 78 | #print ('DINNER FOOD ITEMS') 79 | #print (Dinnerfoodseparated) 80 | 81 | # retrieving rows by loc method | 82 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 83 | print(LunchfoodseparatedID) 84 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 85 | val=list(np.arange(5,15)) 86 | Valapnd=[0]+val 87 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 88 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 89 | #print (LunchfoodseparatedIDdata) 90 | 91 | # retrieving rows by loc method 92 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 93 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 94 | val=list(np.arange(5,15)) 95 | Valapnd=[0]+val 96 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 97 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 98 | #print (breakfastfoodseparatedIDdata) 99 | 100 | 101 | # retrieving rows by loc method 102 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 103 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 104 | val=list(np.arange(5,15)) 105 | Valapnd=[0]+val 106 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 107 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 108 | #print (DinnerfoodseparatedIDdata) 109 | #print (DinnerfoodseparatedIDdata.describe()) 110 | #DinnerfoodseparatedIDdata.iloc[] 111 | 112 | 113 | # In[47]: 114 | age=int(e1.get()) 115 | veg=float(e2.get()) 116 | weight=float(e3.get()) 117 | height=float(e4.get()) 118 | bmi = weight/(height**2) 119 | agewiseinp=0 120 | 121 | for lp in range (0,80,20): 122 | test_list=np.arange(lp,lp+20) 123 | for i in test_list: 124 | if(i == age): 125 | print('age is between',str(lp),str(lp+10)) 126 | tr=round(lp/20) 127 | agecl=round(lp/20) 128 | # In[280]: 129 | 130 | 131 | #conditions 132 | print("Your body mass index is: ", bmi) 133 | if ( bmi < 16): 134 | print("severely underweight") 135 | clbmi=4 136 | elif ( bmi >= 16 and bmi < 18.5): 137 | print("underweight") 138 | clbmi=3 139 | elif ( bmi >= 18.5 and bmi < 25): 140 | print("Healthy") 141 | clbmi=2 142 | elif ( bmi >= 25 and bmi < 30): 143 | print("overweight") 144 | clbmi=1 145 | elif ( bmi >=30): 146 | print("severely overweight") 147 | clbmi=0 148 | val1=DinnerfoodseparatedIDdata.describe() 149 | valTog=val1.T 150 | print (valTog.shape) 151 | print (valTog) 152 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 153 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 154 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 155 | ti=(clbmi+agecl)/2 156 | #print(val) 157 | #print (val.iloc[6]) ##75 percenct data 158 | #print (val.iloc[5]) ##50 percenct data 159 | #print (val.iloc[4]) ##50 percenct data 160 | #dt=np.delete(DinnerfoodseparatedIDdata, [1,3], axis=1) 161 | #print (dt) 162 | 163 | # In[132]: 164 | ## K-Means Based Dinner Food 165 | import matplotlib.pyplot as plt 166 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 167 | #print(Datacalorie) 168 | X = np.array(Datacalorie) 169 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 170 | print ('## Prediction Result ##') 171 | print(kmeans.labels_) 172 | print (kmeans.predict([Datacalorie[0]])) 173 | XValu=np.arange(0,len(kmeans.labels_)) 174 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 175 | # plt.bar(XValu,kmeans.labels_) 176 | dnrlbl=kmeans.labels_ 177 | # plt.title("Predicted Low-High Weigted Calorie Foods") 178 | # In[49]: 179 | ## K-Means Based lunch Food 180 | import matplotlib.pyplot as plt 181 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 182 | #print(Datacalorie) 183 | X = np.array(Datacalorie) 184 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 185 | print ('## Prediction Result ##') 186 | print(kmeans.labels_) 187 | XValu=np.arange(0,len(kmeans.labels_)) 188 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 189 | # plt.bar(XValu,kmeans.labels_) 190 | lnchlbl=kmeans.labels_ 191 | # plt.title("Predicted Low-High Weigted Calorie Foods") 192 | # In[128]: 193 | ## K-Means Based lunch Food 194 | import matplotlib.pyplot as plt 195 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 196 | #print(Datacalorie) 197 | X = np.array(Datacalorie) 198 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 199 | print ('## Prediction Result ##') 200 | print(kmeans.labels_) 201 | XValu=np.arange(0,len(kmeans.labels_)) 202 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 203 | # plt.bar(XValu,kmeans.labels_) 204 | brklbl=kmeans.labels_ 205 | # print (len(brklbl)) 206 | # plt.title("Predicted Low-High Weigted Calorie Foods") 207 | inp=[] 208 | ## Reading of the Dataet 209 | datafin=pd.read_csv('inputfin.csv') 210 | datafin.head(5) 211 | ## train set 212 | #arrayfin=[agecl,clbmi,] 213 | #agebmidatacombiningandprocesseddata(kmeans) 214 | dataTog=datafin.T 215 | bmicls=[0,1,2,3,4] 216 | agecls=[0,1,2,3,4] 217 | weightlosscat = dataTog.iloc[[1,2,7,8]] 218 | weightlosscat=weightlosscat.T 219 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 220 | weightgaincat=weightgaincat.T 221 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 222 | healthycat=healthycat.T 223 | weightlosscatDdata=weightlosscat.to_numpy() 224 | weightgaincatDdata=weightgaincat.to_numpy() 225 | healthycatDdata=healthycat.to_numpy() 226 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 227 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 228 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 229 | 230 | #print(weightgaincat) 231 | #print (len(weightlosscat)) 232 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 233 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 234 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 235 | t=0 236 | r=0 237 | s=0 238 | yt=[] 239 | yr=[] 240 | ys=[] 241 | for zz in range(5): 242 | for jj in range(len(weightlosscat)): 243 | valloc=list(weightlosscat[jj]) 244 | valloc.append(bmicls[zz]) 245 | valloc.append(agecls[zz]) 246 | weightlossfin[t]=np.array(valloc) 247 | yt.append(brklbl[jj]) 248 | t+=1 249 | for jj in range(len(weightgaincat)): 250 | valloc=list(weightgaincat[jj]) 251 | valloc.append(bmicls[zz]) 252 | valloc.append(agecls[zz]) 253 | weightgainfin[r]=np.array(valloc) 254 | yr.append(lnchlbl[jj]) 255 | r+=1 256 | for jj in range(len(healthycat)): 257 | valloc=list(healthycat[jj]) 258 | valloc.append(bmicls[zz]) 259 | valloc.append(agecls[zz]) 260 | healthycatfin[s]=np.array(valloc) 261 | ys.append(dnrlbl[jj]) 262 | s+=1 263 | 264 | 265 | X_test=np.zeros((len(weightlosscat),6),dtype=np.float32) 266 | 267 | print('####################') 268 | # In[287]: 269 | #randomforest 270 | for jj in range(len(weightlosscat)): 271 | valloc=list(weightlosscat[jj]) 272 | valloc.append(agecl) 273 | valloc.append(clbmi) 274 | X_test[jj]=np.array(valloc)*ti 275 | # print (X_test) 276 | # print (len(weightlosscat)) 277 | # print (len(X_test)) 278 | # Import train_test_split function 279 | from sklearn.model_selection import train_test_split 280 | 281 | X_train=weightlossfin# Features 282 | y_train=yt # Labels 283 | 284 | # Split dataset into training set and test set 285 | # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) # 286 | 287 | # Import train_test_split function 288 | from sklearn.model_selection import train_test_split 289 | 290 | X_train= weightlossfin# Features 291 | y_train=yt # Labels 292 | 293 | #Import Random Forest Model 294 | from sklearn.ensemble import RandomForestClassifier 295 | 296 | #Create a Gaussian Classifier 297 | clf=RandomForestClassifier(n_estimators=100) 298 | 299 | #Train the model using the training sets y_pred=clf.predict(X_test) 300 | clf.fit(X_train,y_train) 301 | 302 | print (X_test[1]) 303 | X_test2=X_test 304 | y_pred=clf.predict(X_test) 305 | 306 | 307 | print ('SUGGESTED FOOD ITEMS ::') 308 | for ii in range(len(y_pred)): 309 | if y_pred[ii]==2: #weightloss 310 | print('#################') 311 | print (Food_itemsdata[ii]) 312 | findata=Food_itemsdata[ii] 313 | if int(veg)==1: 314 | datanv=['Chicken Burger'] 315 | for it in range(len(datanv)): 316 | if findata==datanv[it]: 317 | print('VegNovVeg') 318 | 319 | def Weight_Gain(): 320 | print(" Age: %s\n Veg-NonVeg:%s\n Weight%s\n Hight%s\n" % (e1.get(), e2.get(),e3.get(), e4.get())) 321 | print(" Age: %s\n Veg-NonVeg:%s\n Weight%s\n Hight%s\n" % (e1.get(), e2.get(),e3.get(), e4.get())) 322 | #!/usr/bin/env python 323 | # coding: utf-8 324 | import pandas as pd 325 | import numpy as np 326 | import os 327 | 328 | import seaborn as sns 329 | import matplotlib.pyplot as plt 330 | from sklearn.cluster import KMeans 331 | import numpy as np 332 | # # New Section 333 | ## Reading of the Dataet 334 | data=pd.read_csv('input.csv') 335 | data.head(5) 336 | Breakfastdata=data['Breakfast'] 337 | BreakfastdataNumpy=Breakfastdata.to_numpy() 338 | 339 | Lunchdata=data['Lunch'] 340 | LunchdataNumpy=Lunchdata.to_numpy() 341 | 342 | Dinnerdata=data['Dinner'] 343 | DinnerdataNumpy=Dinnerdata.to_numpy() 344 | 345 | Food_itemsdata=data['Food_items'] 346 | breakfastfoodseparated=[] 347 | Lunchfoodseparated=[] 348 | Dinnerfoodseparated=[] 349 | 350 | breakfastfoodseparatedID=[] 351 | LunchfoodseparatedID=[] 352 | DinnerfoodseparatedID=[] 353 | 354 | for i in range(len(Breakfastdata)): 355 | if BreakfastdataNumpy[i]==1: 356 | breakfastfoodseparated.append(Food_itemsdata[i]) 357 | breakfastfoodseparatedID.append(i) 358 | if LunchdataNumpy[i]==1: 359 | Lunchfoodseparated.append(Food_itemsdata[i]) 360 | LunchfoodseparatedID.append(i) 361 | if DinnerdataNumpy[i]==1: 362 | Dinnerfoodseparated.append(Food_itemsdata[i]) 363 | DinnerfoodseparatedID.append(i) 364 | 365 | #print ('BREAKFAST FOOD ITEMS') 366 | #print (breakfastfoodseparated) 367 | #print ('LUNCH FOOD ITEMS') 368 | #print (Lunchfoodseparated) 369 | #print ('DINNER FOOD ITEMS') 370 | #print (Dinnerfoodseparated) 371 | 372 | # retrieving rows by loc method | 373 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 374 | print(LunchfoodseparatedID) 375 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 376 | val=list(np.arange(5,15)) 377 | Valapnd=[0]+val 378 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 379 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 380 | #print (LunchfoodseparatedIDdata) 381 | 382 | # retrieving rows by loc method 383 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 384 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 385 | val=list(np.arange(5,15)) 386 | Valapnd=[0]+val 387 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 388 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 389 | #print (breakfastfoodseparatedIDdata) 390 | 391 | 392 | # retrieving rows by loc method 393 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 394 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 395 | val=list(np.arange(5,15)) 396 | Valapnd=[0]+val 397 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 398 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 399 | #print (DinnerfoodseparatedIDdata) 400 | #print (DinnerfoodseparatedIDdata.describe()) 401 | #DinnerfoodseparatedIDdata.iloc[] 402 | 403 | 404 | # In[47]: 405 | age=int(e1.get()) 406 | veg=float(e2.get()) 407 | weight=float(e3.get()) 408 | height=float(e4.get()) 409 | bmi = weight/(height**2) 410 | agewiseinp=0 411 | 412 | for lp in range (0,80,20): 413 | test_list=np.arange(lp,lp+20) 414 | for i in test_list: 415 | if(i == age): 416 | print('age is between',str(lp),str(lp+10)) 417 | tr=round(lp/20) 418 | agecl=round(lp/20) 419 | # In[280]: 420 | 421 | 422 | #conditions 423 | print("Your body mass index is: ", bmi) 424 | if ( bmi < 16): 425 | print("severely underweight") 426 | clbmi=4 427 | elif ( bmi >= 16 and bmi < 18.5): 428 | print("underweight") 429 | clbmi=3 430 | elif ( bmi >= 18.5 and bmi < 25): 431 | print("Healthy") 432 | clbmi=2 433 | elif ( bmi >= 25 and bmi < 30): 434 | print("overweight") 435 | clbmi=1 436 | elif ( bmi >=30): 437 | print("severely overweight") 438 | clbmi=0 439 | val1=DinnerfoodseparatedIDdata.describe() 440 | valTog=val1.T 441 | print (valTog.shape) 442 | print (valTog) 443 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 444 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 445 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 446 | ti=(bmi+agecl)/2 447 | #print(val) 448 | #print (val.iloc[6]) ##75 percenct data 449 | #print (val.iloc[5]) ##50 percenct data 450 | #print (val.iloc[4]) ##50 percenct data 451 | #dt=np.delete(DinnerfoodseparatedIDdata, [1,3], axis=1) 452 | #print (dt) 453 | 454 | # In[132]: 455 | ## K-Means Based Dinner Food 456 | import matplotlib.pyplot as plt 457 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 458 | #print(Datacalorie) 459 | X = np.array(Datacalorie) 460 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 461 | print ('## Prediction Result ##') 462 | print(kmeans.labels_) 463 | print (kmeans.predict([Datacalorie[0]])) 464 | XValu=np.arange(0,len(kmeans.labels_)) 465 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 466 | # plt.bar(XValu,kmeans.labels_) 467 | dnrlbl=kmeans.labels_ 468 | # plt.title("Predicted Low-High Weigted Calorie Foods") 469 | # In[49]: 470 | ## K-Means Based lunch Food 471 | import matplotlib.pyplot as plt 472 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 473 | #print(Datacalorie) 474 | X = np.array(Datacalorie) 475 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 476 | print ('## Prediction Result ##') 477 | print(kmeans.labels_) 478 | XValu=np.arange(0,len(kmeans.labels_)) 479 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 480 | # plt.bar(XValu,kmeans.labels_) 481 | lnchlbl=kmeans.labels_ 482 | # plt.title("Predicted Low-High Weigted Calorie Foods") 483 | # In[128]: 484 | ## K-Means Based lunch Food 485 | import matplotlib.pyplot as plt 486 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 487 | #print(Datacalorie) 488 | X = np.array(Datacalorie) 489 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 490 | print ('## Prediction Result ##') 491 | print(kmeans.labels_) 492 | XValu=np.arange(0,len(kmeans.labels_)) 493 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 494 | # plt.bar(XValu,kmeans.labels_) 495 | brklbl=kmeans.labels_ 496 | # print (len(brklbl)) 497 | # plt.title("Predicted Low-High Weigted Calorie Foods") 498 | inp=[] 499 | ## Reading of the Dataet 500 | datafin=pd.read_csv('inputfin.csv') 501 | datafin.head(5) 502 | ## train set 503 | #arrayfin=[agecl,clbmi,] 504 | dataTog=datafin.T 505 | bmicls=[0,1,2,3,4] 506 | agecls=[0,1,2,3,4] 507 | weightlosscat = dataTog.iloc[[1,2,7,8]] 508 | weightlosscat=weightlosscat.T 509 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 510 | weightgaincat=weightgaincat.T 511 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 512 | healthycat=healthycat.T 513 | weightlosscatDdata=weightlosscat.to_numpy() 514 | weightgaincatDdata=weightgaincat.to_numpy() 515 | healthycatDdata=healthycat.to_numpy() 516 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 517 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 518 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 519 | 520 | #print(weightgaincat) 521 | #print (len(weightlosscat)) 522 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 523 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 524 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 525 | t=0 526 | r=0 527 | s=0 528 | yt=[] 529 | yr=[] 530 | ys=[] 531 | for zz in range(5): 532 | for jj in range(len(weightlosscat)): 533 | valloc=list(weightlosscat[jj]) 534 | valloc.append(bmicls[zz]) 535 | valloc.append(agecls[zz]) 536 | weightlossfin[t]=np.array(valloc) 537 | yt.append(brklbl[jj]) 538 | t+=1 539 | for jj in range(len(weightgaincat)): 540 | valloc=list(weightgaincat[jj]) 541 | print (valloc) 542 | valloc.append(bmicls[zz]) 543 | valloc.append(agecls[zz]) 544 | weightgainfin[r]=np.array(valloc) 545 | yr.append(lnchlbl[jj]) 546 | r+=1 547 | for jj in range(len(healthycat)): 548 | valloc=list(healthycat[jj]) 549 | valloc.append(bmicls[zz]) 550 | valloc.append(agecls[zz]) 551 | healthycatfin[s]=np.array(valloc) 552 | ys.append(dnrlbl[jj]) 553 | s+=1 554 | 555 | 556 | X_test=np.zeros((len(weightgaincat),10),dtype=np.float32) 557 | 558 | print('####################') 559 | # In[287]: 560 | for jj in range(len(weightgaincat)): 561 | valloc=list(weightgaincat[jj]) 562 | valloc.append(agecl) 563 | valloc.append(clbmi) 564 | X_test[jj]=np.array(valloc)*ti 565 | # print (X_test) 566 | # print (len(weightlosscat)) 567 | print (weightgainfin.shape) 568 | # Import train_test_split function 569 | from sklearn.model_selection import train_test_split 570 | 571 | X_train=weightgainfin# Features 572 | y_train=yr # Labels 573 | 574 | # Split dataset into training set and test set 575 | # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) # 576 | 577 | # Import train_test_split function 578 | from sklearn.model_selection import train_test_split 579 | 580 | # X_train= weightlossfin# Features 581 | # y_train=yt # Labels 582 | 583 | #Import Random Forest Model 584 | from sklearn.ensemble import RandomForestClassifier 585 | 586 | #Create a Gaussian Classifier 587 | clf=RandomForestClassifier(n_estimators=100) 588 | 589 | #Train the model using the training sets y_pred=clf.predict(X_test) 590 | clf.fit(X_train,y_train) 591 | 592 | print (X_test[1]) 593 | X_test2=X_test 594 | y_pred=clf.predict(X_test) 595 | print('ok') 596 | 597 | 598 | print ('SUGGESTED FOOD ITEMS ::') 599 | for ii in range(len(y_pred)): 600 | if y_pred[ii]==2: 601 | print('#################') 602 | print (Food_itemsdata[ii]) 603 | findata=Food_itemsdata[ii] 604 | if int(veg)==1: 605 | datanv=['Chicken Burger'] 606 | for it in range(len(datanv)): 607 | if findata==datanv[it]: 608 | print('VegNovVeg') 609 | def Healthy(): 610 | print(" Age: %s\n Veg-NonVeg:%s\n Weight%s\n Hight%s\n" % (e1.get(), e2.get(),e3.get(), e4.get())) 611 | #!/usr/bin/env python 612 | # coding: utf-8 613 | import pandas as pd 614 | import numpy as np 615 | import os 616 | 617 | import seaborn as sns 618 | import matplotlib.pyplot as plt 619 | from sklearn.cluster import KMeans 620 | import numpy as np 621 | # # New Section 622 | ## Reading of the Dataet 623 | data=pd.read_csv('input.csv') 624 | data.head(5) 625 | Breakfastdata=data['Breakfast'] 626 | BreakfastdataNumpy=Breakfastdata.to_numpy() 627 | 628 | Lunchdata=data['Lunch'] 629 | LunchdataNumpy=Lunchdata.to_numpy() 630 | 631 | Dinnerdata=data['Dinner'] 632 | DinnerdataNumpy=Dinnerdata.to_numpy() 633 | 634 | Food_itemsdata=data['Food_items'] 635 | breakfastfoodseparated=[] 636 | Lunchfoodseparated=[] 637 | Dinnerfoodseparated=[] 638 | 639 | breakfastfoodseparatedID=[] 640 | LunchfoodseparatedID=[] 641 | DinnerfoodseparatedID=[] 642 | 643 | for i in range(len(Breakfastdata)): 644 | if BreakfastdataNumpy[i]==1: 645 | breakfastfoodseparated.append(Food_itemsdata[i]) 646 | breakfastfoodseparatedID.append(i) 647 | if LunchdataNumpy[i]==1: 648 | Lunchfoodseparated.append(Food_itemsdata[i]) 649 | LunchfoodseparatedID.append(i) 650 | if DinnerdataNumpy[i]==1: 651 | Dinnerfoodseparated.append(Food_itemsdata[i]) 652 | DinnerfoodseparatedID.append(i) 653 | 654 | #print ('BREAKFAST FOOD ITEMS') 655 | #print (breakfastfoodseparated) 656 | #print ('LUNCH FOOD ITEMS') 657 | #print (Lunchfoodseparated) 658 | #print ('DINNER FOOD ITEMS') 659 | #print (Dinnerfoodseparated) 660 | 661 | # retrieving rows by loc method | 662 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 663 | print(LunchfoodseparatedID) 664 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 665 | val=list(np.arange(5,15)) 666 | Valapnd=[0]+val 667 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 668 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 669 | #print (LunchfoodseparatedIDdata) 670 | 671 | # retrieving rows by loc method 672 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 673 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 674 | val=list(np.arange(5,15)) 675 | Valapnd=[0]+val 676 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 677 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 678 | #print (breakfastfoodseparatedIDdata) 679 | 680 | 681 | # retrieving rows by loc method 682 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 683 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 684 | val=list(np.arange(5,15)) 685 | Valapnd=[0]+val 686 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 687 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 688 | #print (DinnerfoodseparatedIDdata) 689 | #print (DinnerfoodseparatedIDdata.describe()) 690 | #DinnerfoodseparatedIDdata.iloc[] 691 | 692 | 693 | # In[47]: 694 | age=int(e1.get()) 695 | veg=float(e2.get()) 696 | weight=float(e3.get()) 697 | height=float(e4.get()) 698 | bmi = weight/(height**2) 699 | agewiseinp=0 700 | 701 | for lp in range (0,80,20): 702 | test_list=np.arange(lp,lp+20) 703 | for i in test_list: 704 | if(i == age): 705 | print('age is between',str(lp),str(lp+10)) 706 | tr=round(lp/20) 707 | agecl=round(lp/20) 708 | # In[280]: 709 | 710 | 711 | #conditions 712 | print("Your body mass index is: ", bmi) 713 | if ( bmi < 16): 714 | print("severely underweight") 715 | clbmi=4 716 | elif ( bmi >= 16 and bmi < 18.5): 717 | print("underweight") 718 | clbmi=3 719 | elif ( bmi >= 18.5 and bmi < 25): 720 | print("Healthy") 721 | clbmi=2 722 | elif ( bmi >= 25 and bmi < 30): 723 | print("overweight") 724 | clbmi=1 725 | elif ( bmi >=30): 726 | print("severely overweight") 727 | clbmi=0 728 | val1=DinnerfoodseparatedIDdata.describe() 729 | valTog=val1.T 730 | print (valTog.shape) 731 | print (valTog) 732 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 733 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 734 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 735 | ti=(bmi+agecl)/2 736 | #print(val) 737 | #print (val.iloc[6]) ##75 percenct data 738 | #print (val.iloc[5]) ##50 percenct data 739 | #print (val.iloc[4]) ##50 percenct data 740 | #dt=np.delete(DinnerfoodseparatedIDdata, [1,3], axis=1) 741 | #print (dt) 742 | 743 | # In[132]: 744 | ## K-Means Based Dinner Food 745 | import matplotlib.pyplot as plt 746 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 747 | #print(Datacalorie) 748 | X = np.array(Datacalorie) 749 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 750 | print ('## Prediction Result ##') 751 | print(kmeans.labels_) 752 | print (kmeans.predict([Datacalorie[0]])) 753 | XValu=np.arange(0,len(kmeans.labels_)) 754 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 755 | # plt.bar(XValu,kmeans.labels_) 756 | dnrlbl=kmeans.labels_ 757 | # plt.title("Predicted Low-High Weigted Calorie Foods") 758 | # In[49]: 759 | ## K-Means Based lunch Food 760 | import matplotlib.pyplot as plt 761 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 762 | #print(Datacalorie) 763 | X = np.array(Datacalorie) 764 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 765 | print ('## Prediction Result ##') 766 | print(kmeans.labels_) 767 | XValu=np.arange(0,len(kmeans.labels_)) 768 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 769 | # plt.bar(XValu,kmeans.labels_) 770 | lnchlbl=kmeans.labels_ 771 | # plt.title("Predicted Low-High Weigted Calorie Foods") 772 | # In[128]: 773 | ## K-Means Based lunch Food 774 | import matplotlib.pyplot as plt 775 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 776 | #print(Datacalorie) 777 | X = np.array(Datacalorie) 778 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 779 | print ('## Prediction Result ##') 780 | print(kmeans.labels_) 781 | XValu=np.arange(0,len(kmeans.labels_)) 782 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 783 | # plt.bar(XValu,kmeans.labels_) 784 | brklbl=kmeans.labels_ 785 | # print (len(brklbl)) 786 | # plt.title("Predicted Low-High Weigted Calorie Foods") 787 | inp=[] 788 | ## Reading of the Dataet 789 | datafin=pd.read_csv('inputfin.csv') 790 | datafin.head(5) 791 | ## train set 792 | #arrayfin=[agecl,clbmi,] 793 | dataTog=datafin.T 794 | bmicls=[0,1,2,3,4] 795 | agecls=[0,1,2,3,4] 796 | weightlosscat = dataTog.iloc[[1,2,7,8]] 797 | weightlosscat=weightlosscat.T 798 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 799 | weightgaincat=weightgaincat.T 800 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 801 | healthycat=healthycat.T 802 | weightlosscatDdata=weightlosscat.to_numpy() 803 | weightgaincatDdata=weightgaincat.to_numpy() 804 | healthycatDdata=healthycat.to_numpy() 805 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 806 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 807 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 808 | 809 | #print(weightgaincat) 810 | #print (len(weightlosscat)) 811 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 812 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 813 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 814 | t=0 815 | r=0 816 | s=0 817 | yt=[] 818 | yr=[] 819 | ys=[] 820 | for zz in range(5): 821 | for jj in range(len(weightlosscat)): 822 | valloc=list(weightlosscat[jj]) 823 | valloc.append(bmicls[zz]) 824 | valloc.append(agecls[zz]) 825 | weightlossfin[t]=np.array(valloc) 826 | yt.append(brklbl[jj]) 827 | t+=1 828 | for jj in range(len(weightgaincat)): 829 | valloc=list(weightgaincat[jj]) 830 | print (valloc) 831 | valloc.append(bmicls[zz]) 832 | valloc.append(agecls[zz]) 833 | weightgainfin[r]=np.array(valloc) 834 | yr.append(lnchlbl[jj]) 835 | r+=1 836 | for jj in range(len(healthycat)): 837 | valloc=list(healthycat[jj]) 838 | valloc.append(bmicls[zz]) 839 | valloc.append(agecls[zz]) 840 | healthycatfin[s]=np.array(valloc) 841 | ys.append(dnrlbl[jj]) 842 | s+=1 843 | 844 | X_test=np.zeros((len(healthycat)*5,9),dtype=np.float32) 845 | print('####################') 846 | # In[287]: 847 | for jj in range(len(healthycat)): 848 | valloc=list(healthycat[jj]) 849 | valloc.append(agecl) 850 | valloc.append(clbmi) 851 | X_test[jj]=np.array(valloc)*ti 852 | # print (X_test) 853 | # print (len(weightlosscat)) 854 | print (weightgainfin.shape) 855 | # Import train_test_split function 856 | from sklearn.model_selection import train_test_split 857 | 858 | X_train=healthycatfin# Features 859 | y_train=ys # Labels 860 | 861 | # Split dataset into training set and test set 862 | # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) # 863 | 864 | # Import train_test_split function 865 | from sklearn.model_selection import train_test_split 866 | 867 | # X_train= weightlossfin# Features 868 | # y_train=yt # Labels 869 | 870 | #Import Random Forest Model 871 | from sklearn.ensemble import RandomForestClassifier 872 | 873 | #Create a Gaussian Classifier 874 | clf=RandomForestClassifier(n_estimators=100) 875 | 876 | #Train the model using the training sets y_pred=clf.predict(X_test) 877 | clf.fit(X_train,y_train) 878 | 879 | print (X_test[1]) 880 | X_test2=X_test 881 | y_pred=clf.predict(X_test) 882 | print('ok') 883 | 884 | 885 | print ('SUGGESTED FOOD ITEMS ::') 886 | for ii in range(len(y_pred)): 887 | if y_pred[ii]==2: 888 | print('#################') 889 | print (Food_itemsdata[ii]) 890 | findata=Food_itemsdata[ii] 891 | if int(veg)==1: 892 | datanv=['Chicken Burger'] 893 | for it in range(len(datanv)): 894 | if findata==datanv[it]: 895 | print('VegNovVeg') 896 | 897 | #master = tk.Tk() 898 | Label(main_win,text="Age").grid(row=0,column=0,sticky=W,pady=4) 899 | Label(main_win,text="veg/Non veg").grid(row=1,column=0,sticky=W,pady=4) 900 | Label(main_win,text="Weight").grid(row=2,column=0,sticky=W,pady=4) 901 | Label(main_win,text="Height").grid(row=3,column=0,sticky=W,pady=4) 902 | # Label(main_win,text="Age").grid(row=2,column=0) 903 | 904 | e1 = Entry(main_win) 905 | e2 = Entry(main_win) 906 | e3 = Entry(main_win) 907 | e4 = Entry(main_win) 908 | 909 | e1.grid(row=0, column=1) 910 | e2.grid(row=1, column=1) 911 | e3.grid(row=2, column=1) 912 | e4.grid(row=3, column=1) 913 | 914 | Button(main_win,text='Quit',command=main_win.quit).grid(row=5,column=0,sticky=W,pady=4) 915 | Button(main_win,text='Weight Loss',command=Weight_Loss).grid(row=1,column=4,sticky=W,pady=4) 916 | Button(main_win,text='Weight Gain',command=Weight_Gain).grid(row=2,column=4,sticky=W,pady=4) 917 | Button(main_win,text='Healthy',command=Healthy).grid(row=3,column=4,sticky=W,pady=4) 918 | main_win.geometry("400x200") 919 | main_win.wm_title("DIET RECOMMENDATION SYSTEM") 920 | #GUIEXECUTION 921 | main_win.mainloop() 922 | --------------------------------------------------------------------------------