├── CSE508 KNOWLEDGE BASED EXPERT SYSTEMS.pdf ├── Diet Recommendation System.ipynb ├── README.md ├── diet_recommender.py ├── food.csv └── nutrition_distriution.csv /CSE508 KNOWLEDGE BASED EXPERT SYSTEMS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vishal-shyftlabs/ML_project/8ac3b99280a89fb375c433fc0a366c9b7f106a98/CSE508 KNOWLEDGE BASED EXPERT SYSTEMS.pdf -------------------------------------------------------------------------------- /Diet Recommendation System.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "\n", 13 | " Age: 21\n", 14 | " Veg-NonVeg: 1\n", 15 | " Weight: 78 kg\n", 16 | " Hight: 180 cm\n", 17 | "\n", 18 | "Your body mass index is: 24.074074074074073\n", 19 | "Acoording to your BMI, you are Healthy\n", 20 | "####################\n", 21 | "SUGGESTED FOOD ITEMS ::\n", 22 | "Cauliflower\n", 23 | "Corn\n", 24 | "Grapes\n", 25 | "Pumpkin\n", 26 | "Sugar Doughnuts\n", 27 | "Poha\n", 28 | "Tomato\n", 29 | "Brownie\n", 30 | "\n", 31 | " Thank You for taking our recommendations. :)\n", 32 | "\n", 33 | " Age: 21\n", 34 | " Veg-NonVeg: 1\n", 35 | " Weight: 78 kg\n", 36 | " Hight: 180 cm\n", 37 | "\n", 38 | "Your body mass index is: 24.074074074074073\n", 39 | "Acoording to your BMI, you are Healthy\n", 40 | "####################\n", 41 | "SUGGESTED FOOD ITEMS ::\n", 42 | "Asparagus Cooked\n", 43 | "Berries\n", 44 | "Brocolli\n", 45 | "Coffee\n", 46 | "Dark chocolates\n", 47 | "Pasta canned with tomato sauce\n", 48 | "French Fries\n", 49 | "Chicken Burger\n", 50 | "VegNovVeg\n", 51 | "Cheese Burger\n", 52 | "Chocolate Doughnuts\n", 53 | "Pop Corn\n", 54 | "Dosa\n", 55 | "Poha\n", 56 | "Yogurt\n", 57 | "\n", 58 | " Thank You for taking our recommendations. :)\n", 59 | "\n", 60 | " Age: 21\n", 61 | " Veg-NonVeg: 1\n", 62 | " Weight: 78 kg\n", 63 | " Hight: 180 cm\n", 64 | "\n", 65 | "Your body mass index is: 24.074074074074073\n", 66 | "Acoording to your BMI, you are Healthy\n", 67 | "####################\n", 68 | "SUGGESTED FOOD ITEMS ::\n", 69 | "Berries\n", 70 | "Brocolli\n", 71 | "Coffee\n", 72 | "Cashew Nuts\n", 73 | "French Fries\n", 74 | "Chicken Burger\n", 75 | "VegNovVeg\n", 76 | "Cheese Burger\n", 77 | "Chocolate Doughnuts\n", 78 | "Pop Corn\n", 79 | "Dosa\n", 80 | "Idli\n", 81 | "Yogurt\n", 82 | "\n", 83 | " Thank You for taking our recommendations. :)\n", 84 | "\n", 85 | " Age: 21\n", 86 | " Veg-NonVeg: 1\n", 87 | " Weight: 78 kg\n", 88 | " Hight: 180 cm\n", 89 | "\n", 90 | "Your body mass index is: 24.074074074074073\n", 91 | "Acoording to your BMI, you are Healthy\n", 92 | "SUGGESTED FOOD ITEMS ::\n", 93 | "Asparagus Cooked\n", 94 | "Bananas\n", 95 | "Berries\n", 96 | "Brocolli\n", 97 | "Brown Rice\n", 98 | "American cheese\n", 99 | "Corn\n", 100 | "Dark chocolates\n", 101 | "Onions\n", 102 | "Orange\n", 103 | "Pasta canned with tomato sauce\n", 104 | "Protein Powder\n", 105 | "Tuna Salad\n", 106 | "Tuna Fish\n", 107 | "Peproni Pizza\n", 108 | "Cheese Pizza\n", 109 | "French Fries\n", 110 | "Chicken Burger\n", 111 | "Cheese Burger\n", 112 | "Chocolate Doughnuts\n", 113 | "Pop Corn - Caramel\n", 114 | "Idli\n", 115 | "\n", 116 | " Thank You for taking our recommendations. :)\n" 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "import pandas as pd\n", 122 | "import numpy as np\n", 123 | "from tkinter import *\n", 124 | "from sklearn.cluster import KMeans\n", 125 | "from sklearn.model_selection import train_test_split\n", 126 | "from sklearn.ensemble import RandomForestClassifier\n", 127 | "\n", 128 | "data=pd.read_csv('food.csv')\n", 129 | "Breakfastdata=data['Breakfast']\n", 130 | "BreakfastdataNumpy=Breakfastdata.to_numpy()\n", 131 | " \n", 132 | "Lunchdata=data['Lunch']\n", 133 | "LunchdataNumpy=Lunchdata.to_numpy()\n", 134 | " \n", 135 | "Dinnerdata=data['Dinner']\n", 136 | "DinnerdataNumpy=Dinnerdata.to_numpy()\n", 137 | "Food_itemsdata=data['Food_items']\n", 138 | "\n", 139 | "\n", 140 | "\n", 141 | "def show_entry_fields():\n", 142 | " print(\"\\n Age: %s\\n Veg-NonVeg: %s\\n Weight: %s kg\\n Hight: %s cm\\n\" % (e1.get(), e2.get(),e3.get(), e4.get()))\n", 143 | "\n", 144 | "\n", 145 | "def Weight_Loss():\n", 146 | " show_entry_fields()\n", 147 | " \n", 148 | " breakfastfoodseparated=[]\n", 149 | " Lunchfoodseparated=[]\n", 150 | " Dinnerfoodseparated=[]\n", 151 | " \n", 152 | " breakfastfoodseparatedID=[]\n", 153 | " LunchfoodseparatedID=[]\n", 154 | " DinnerfoodseparatedID=[]\n", 155 | " \n", 156 | " for i in range(len(Breakfastdata)):\n", 157 | " if BreakfastdataNumpy[i]==1:\n", 158 | " breakfastfoodseparated.append( Food_itemsdata[i] )\n", 159 | " breakfastfoodseparatedID.append(i)\n", 160 | " if LunchdataNumpy[i]==1:\n", 161 | " Lunchfoodseparated.append(Food_itemsdata[i])\n", 162 | " LunchfoodseparatedID.append(i)\n", 163 | " if DinnerdataNumpy[i]==1:\n", 164 | " Dinnerfoodseparated.append(Food_itemsdata[i])\n", 165 | " DinnerfoodseparatedID.append(i)\n", 166 | " \n", 167 | " # retrieving Lunch data rows by loc method |\n", 168 | " LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID]\n", 169 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T\n", 170 | " #print(LunchfoodseparatedIDdata)\n", 171 | " val=list(np.arange(5,15))\n", 172 | " Valapnd=[0]+val\n", 173 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd]\n", 174 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T\n", 175 | " #print(LunchfoodseparatedIDdata)\n", 176 | "\n", 177 | " # retrieving Breafast data rows by loc method \n", 178 | " breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID]\n", 179 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T\n", 180 | " val=list(np.arange(5,15))\n", 181 | " Valapnd=[0]+val\n", 182 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd]\n", 183 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T\n", 184 | " \n", 185 | " \n", 186 | " # retrieving Dinner Data rows by loc method \n", 187 | " DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID]\n", 188 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T\n", 189 | " val=list(np.arange(5,15))\n", 190 | " Valapnd=[0]+val\n", 191 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd]\n", 192 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T\n", 193 | " \n", 194 | " #calculating BMI\n", 195 | " age=int(e1.get())\n", 196 | " veg=float(e2.get())\n", 197 | " weight=float(e3.get())\n", 198 | " height=float(e4.get())\n", 199 | " bmi = weight/((height/100)**2) \n", 200 | " agewiseinp=0\n", 201 | " \n", 202 | " for lp in range (0,80,20):\n", 203 | " test_list=np.arange(lp,lp+20)\n", 204 | " for i in test_list: \n", 205 | " if(i == age):\n", 206 | " tr=round(lp/20) \n", 207 | " agecl=round(lp/20) \n", 208 | "\n", 209 | " \n", 210 | " #conditions\n", 211 | " print(\"Your body mass index is: \", bmi)\n", 212 | " if ( bmi < 16):\n", 213 | " print(\"Acoording to your BMI, you are Severely Underweight\")\n", 214 | " clbmi=4\n", 215 | " elif ( bmi >= 16 and bmi < 18.5):\n", 216 | " print(\"Acoording to your BMI, you are Underweight\")\n", 217 | " clbmi=3\n", 218 | " elif ( bmi >= 18.5 and bmi < 25):\n", 219 | " print(\"Acoording to your BMI, you are Healthy\")\n", 220 | " clbmi=2\n", 221 | " elif ( bmi >= 25 and bmi < 30):\n", 222 | " print(\"Acoording to your BMI, you are Overweight\")\n", 223 | " clbmi=1\n", 224 | " elif ( bmi >=30):\n", 225 | " print(\"Acoording to your BMI, you are Severely Overweight\")\n", 226 | " clbmi=0\n", 227 | "\n", 228 | " #converting into numpy array\n", 229 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy()\n", 230 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy()\n", 231 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy()\n", 232 | " ti=(clbmi+agecl)/2\n", 233 | " \n", 234 | " ## K-Means Based Dinner Food\n", 235 | " Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)]\n", 236 | "\n", 237 | " X = np.array(Datacalorie)\n", 238 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 239 | "\n", 240 | " XValu=np.arange(0,len(kmeans.labels_))\n", 241 | " \n", 242 | " # retrieving the labels for dinner food\n", 243 | " dnrlbl=kmeans.labels_\n", 244 | "\n", 245 | " ## K-Means Based lunch Food\n", 246 | " Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)]\n", 247 | " \n", 248 | " X = np.array(Datacalorie)\n", 249 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 250 | " \n", 251 | " XValu=np.arange(0,len(kmeans.labels_))\n", 252 | " \n", 253 | " # retrieving the labels for lunch food\n", 254 | " lnchlbl=kmeans.labels_\n", 255 | " \n", 256 | " ## K-Means Based lunch Food\n", 257 | " Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)]\n", 258 | " \n", 259 | " X = np.array(Datacalorie)\n", 260 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 261 | " \n", 262 | " XValu=np.arange(0,len(kmeans.labels_))\n", 263 | " \n", 264 | " # retrieving the labels for breakfast food\n", 265 | " brklbl=kmeans.labels_\n", 266 | " \n", 267 | " inp=[]\n", 268 | " ## Reading of the Dataet\n", 269 | " datafin=pd.read_csv('nutrition_distriution.csv')\n", 270 | "\n", 271 | " ## train set\n", 272 | " dataTog=datafin.T\n", 273 | " bmicls=[0,1,2,3,4]\n", 274 | " agecls=[0,1,2,3,4]\n", 275 | " weightlosscat = dataTog.iloc[[1,2,7,8]]\n", 276 | " weightlosscat=weightlosscat.T\n", 277 | " weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]]\n", 278 | " weightgaincat=weightgaincat.T\n", 279 | " healthycat = dataTog.iloc[[1,2,3,4,6,7,9]]\n", 280 | " healthycat=healthycat.T\n", 281 | " weightlosscatDdata=weightlosscat.to_numpy()\n", 282 | " weightgaincatDdata=weightgaincat.to_numpy()\n", 283 | " healthycatDdata=healthycat.to_numpy()\n", 284 | " weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)]\n", 285 | " weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)]\n", 286 | " healthycat=healthycatDdata[1:,0:len(healthycatDdata)]\n", 287 | " \n", 288 | " \n", 289 | " weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32)\n", 290 | " weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32)\n", 291 | " healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32)\n", 292 | " t=0\n", 293 | " r=0\n", 294 | " s=0\n", 295 | " yt=[]\n", 296 | " yr=[]\n", 297 | " ys=[]\n", 298 | " for zz in range(5):\n", 299 | " for jj in range(len(weightlosscat)):\n", 300 | " valloc=list(weightlosscat[jj])\n", 301 | " valloc.append(bmicls[zz])\n", 302 | " valloc.append(agecls[zz])\n", 303 | " weightlossfin[t]=np.array(valloc)\n", 304 | " yt.append(brklbl[jj])\n", 305 | " t+=1\n", 306 | " for jj in range(len(weightgaincat)):\n", 307 | " valloc=list(weightgaincat[jj])\n", 308 | " valloc.append(bmicls[zz])\n", 309 | " valloc.append(agecls[zz])\n", 310 | " weightgainfin[r]=np.array(valloc)\n", 311 | " yr.append(lnchlbl[jj])\n", 312 | " r+=1\n", 313 | " for jj in range(len(healthycat)):\n", 314 | " valloc=list(healthycat[jj])\n", 315 | " valloc.append(bmicls[zz])\n", 316 | " valloc.append(agecls[zz])\n", 317 | " healthycatfin[s]=np.array(valloc)\n", 318 | " ys.append(dnrlbl[jj])\n", 319 | " s+=1\n", 320 | "\n", 321 | " \n", 322 | " X_test=np.zeros((len(weightlosscat),6),dtype=np.float32)\n", 323 | "\n", 324 | " print('####################')\n", 325 | " \n", 326 | " #randomforest\n", 327 | " for jj in range(len(weightlosscat)):\n", 328 | " valloc=list(weightlosscat[jj])\n", 329 | " valloc.append(agecl)\n", 330 | " valloc.append(clbmi)\n", 331 | " X_test[jj]=np.array(valloc)*ti\n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " X_train=weightlossfin# Features\n", 336 | " y_train=yt # Labels\n", 337 | "\n", 338 | " #Create a Gaussian Classifier\n", 339 | " clf=RandomForestClassifier(n_estimators=100)\n", 340 | " \n", 341 | " #Train the model using the training sets y_pred=clf.predict(X_test)\n", 342 | " clf.fit(X_train,y_train)\n", 343 | " \n", 344 | " #print (X_test[1])\n", 345 | " X_test2=X_test\n", 346 | " y_pred=clf.predict(X_test)\n", 347 | " \n", 348 | " \n", 349 | " print ('SUGGESTED FOOD ITEMS ::')\n", 350 | " for ii in range(len(y_pred)):\n", 351 | " if y_pred[ii]==2: #weightloss\n", 352 | " print (Food_itemsdata[ii])\n", 353 | " findata=Food_itemsdata[ii]\n", 354 | " if int(veg)==1:\n", 355 | " datanv=['Chicken Burger']\n", 356 | " for it in range(len(datanv)):\n", 357 | " if findata==datanv[it]:\n", 358 | " print('VegNovVeg')\n", 359 | "\n", 360 | " print('\\n Thank You for taking our recommendations. :)')\n", 361 | "\n", 362 | "\n", 363 | "\n", 364 | "\n", 365 | "def Weight_Gain():\n", 366 | " show_entry_fields()\n", 367 | "\n", 368 | " breakfastfoodseparated=[]\n", 369 | " Lunchfoodseparated=[]\n", 370 | " Dinnerfoodseparated=[]\n", 371 | " \n", 372 | " breakfastfoodseparatedID=[]\n", 373 | " LunchfoodseparatedID=[]\n", 374 | " DinnerfoodseparatedID=[]\n", 375 | " \n", 376 | " for i in range(len(Breakfastdata)):\n", 377 | " if BreakfastdataNumpy[i]==1:\n", 378 | " breakfastfoodseparated.append( Food_itemsdata[i] )\n", 379 | " breakfastfoodseparatedID.append(i)\n", 380 | " if LunchdataNumpy[i]==1:\n", 381 | " Lunchfoodseparated.append(Food_itemsdata[i])\n", 382 | " LunchfoodseparatedID.append(i)\n", 383 | " if DinnerdataNumpy[i]==1:\n", 384 | " Dinnerfoodseparated.append(Food_itemsdata[i])\n", 385 | " DinnerfoodseparatedID.append(i)\n", 386 | " \n", 387 | " # retrieving rows by loc method |\n", 388 | " LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID]\n", 389 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T\n", 390 | " val=list(np.arange(5,15))\n", 391 | " Valapnd=[0]+val\n", 392 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd]\n", 393 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T\n", 394 | " \n", 395 | " # retrieving rows by loc method \n", 396 | " breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID]\n", 397 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T\n", 398 | " val=list(np.arange(5,15))\n", 399 | " Valapnd=[0]+val\n", 400 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd]\n", 401 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T\n", 402 | " \n", 403 | " \n", 404 | " # retrieving rows by loc method \n", 405 | " DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID]\n", 406 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T\n", 407 | " val=list(np.arange(5,15))\n", 408 | " Valapnd=[0]+val\n", 409 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd]\n", 410 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T\n", 411 | " \n", 412 | " #claculating BMI\n", 413 | " age=int(e1.get())\n", 414 | " veg=float(e2.get())\n", 415 | " weight=float(e3.get())\n", 416 | " height=float(e4.get())\n", 417 | " bmi = weight/((height/100)**2) \n", 418 | "\n", 419 | " for lp in range (0,80,20):\n", 420 | " test_list=np.arange(lp,lp+20)\n", 421 | " for i in test_list: \n", 422 | " if(i == age):\n", 423 | " tr=round(lp/20) \n", 424 | " agecl=round(lp/20)\n", 425 | "\n", 426 | " print(\"Your body mass index is: \", bmi)\n", 427 | " if ( bmi < 16):\n", 428 | " print(\"Acoording to your BMI, you are Severely Underweight\")\n", 429 | " clbmi=4\n", 430 | " elif ( bmi >= 16 and bmi < 18.5):\n", 431 | " print(\"Acoording to your BMI, you are Underweight\")\n", 432 | " clbmi=3\n", 433 | " elif ( bmi >= 18.5 and bmi < 25):\n", 434 | " print(\"Acoording to your BMI, you are Healthy\")\n", 435 | " clbmi=2\n", 436 | " elif ( bmi >= 25 and bmi < 30):\n", 437 | " print(\"Acoording to your BMI, you are Overweight\")\n", 438 | " clbmi=1\n", 439 | " elif ( bmi >=30):\n", 440 | " print(\"Acoording to your BMI, you are Severely Overweight\")\n", 441 | " clbmi=0\n", 442 | "\n", 443 | "\n", 444 | " \n", 445 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy()\n", 446 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy()\n", 447 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy()\n", 448 | " ti=(bmi+agecl)/2\n", 449 | " \n", 450 | " \n", 451 | " ## K-Means Based Dinner Food\n", 452 | " Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)]\n", 453 | " \n", 454 | " X = np.array(Datacalorie)\n", 455 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 456 | " \n", 457 | " XValu=np.arange(0,len(kmeans.labels_))\n", 458 | " # plt.bar(XValu,kmeans.labels_)\n", 459 | " dnrlbl=kmeans.labels_\n", 460 | " # plt.title(\"Predicted Low-High Weigted Calorie Foods\")\n", 461 | " \n", 462 | " ## K-Means Based lunch Food\n", 463 | " Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)]\n", 464 | " \n", 465 | " X = np.array(Datacalorie)\n", 466 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 467 | " \n", 468 | " XValu=np.arange(0,len(kmeans.labels_))\n", 469 | " # fig,axs=plt.subplots(1,1,figsize=(15,5))\n", 470 | " # plt.bar(XValu,kmeans.labels_)\n", 471 | " lnchlbl=kmeans.labels_\n", 472 | " # plt.title(\"Predicted Low-High Weigted Calorie Foods\")\n", 473 | " \n", 474 | " ## K-Means Based lunch Food\n", 475 | " Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)]\n", 476 | "\n", 477 | " X = np.array(Datacalorie)\n", 478 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 479 | " \n", 480 | " XValu=np.arange(0,len(kmeans.labels_))\n", 481 | " # fig,axs=plt.subplots(1,1,figsize=(15,5))\n", 482 | " # plt.bar(XValu,kmeans.labels_)\n", 483 | " brklbl=kmeans.labels_\n", 484 | " \n", 485 | " # plt.title(\"Predicted Low-High Weigted Calorie Foods\")\n", 486 | " inp=[]\n", 487 | " ## Reading of the Dataet\n", 488 | " datafin=pd.read_csv('nutrition_distriution.csv')\n", 489 | " datafin.head(5)\n", 490 | " \n", 491 | " dataTog=datafin.T\n", 492 | " bmicls=[0,1,2,3,4]\n", 493 | " agecls=[0,1,2,3,4]\n", 494 | " weightlosscat = dataTog.iloc[[1,2,7,8]]\n", 495 | " weightlosscat=weightlosscat.T\n", 496 | " weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]]\n", 497 | " weightgaincat=weightgaincat.T\n", 498 | " healthycat = dataTog.iloc[[1,2,3,4,6,7,9]]\n", 499 | " healthycat=healthycat.T\n", 500 | " weightlosscatDdata=weightlosscat.to_numpy()\n", 501 | " weightgaincatDdata=weightgaincat.to_numpy()\n", 502 | " healthycatDdata=healthycat.to_numpy()\n", 503 | " weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)]\n", 504 | " weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)]\n", 505 | " healthycat=healthycatDdata[1:,0:len(healthycatDdata)]\n", 506 | " \n", 507 | " \n", 508 | " weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32)\n", 509 | " weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32)\n", 510 | " healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32)\n", 511 | " t=0\n", 512 | " r=0\n", 513 | " s=0\n", 514 | " yt=[]\n", 515 | " yr=[]\n", 516 | " ys=[]\n", 517 | " for zz in range(5):\n", 518 | " for jj in range(len(weightlosscat)):\n", 519 | " valloc=list(weightlosscat[jj])\n", 520 | " valloc.append(bmicls[zz])\n", 521 | " valloc.append(agecls[zz])\n", 522 | " weightlossfin[t]=np.array(valloc)\n", 523 | " yt.append(brklbl[jj])\n", 524 | " t+=1\n", 525 | " for jj in range(len(weightgaincat)):\n", 526 | " valloc=list(weightgaincat[jj])\n", 527 | " #print (valloc)\n", 528 | " valloc.append(bmicls[zz])\n", 529 | " valloc.append(agecls[zz])\n", 530 | " weightgainfin[r]=np.array(valloc)\n", 531 | " yr.append(lnchlbl[jj])\n", 532 | " r+=1\n", 533 | " for jj in range(len(healthycat)):\n", 534 | " valloc=list(healthycat[jj])\n", 535 | " valloc.append(bmicls[zz])\n", 536 | " valloc.append(agecls[zz])\n", 537 | " healthycatfin[s]=np.array(valloc)\n", 538 | " ys.append(dnrlbl[jj])\n", 539 | " s+=1\n", 540 | "\n", 541 | " \n", 542 | " X_test=np.zeros((len(weightgaincat),10),dtype=np.float32)\n", 543 | "\n", 544 | " print('####################')\n", 545 | " # In[287]:\n", 546 | " for jj in range(len(weightgaincat)):\n", 547 | " valloc=list(weightgaincat[jj])\n", 548 | " valloc.append(agecl)\n", 549 | " valloc.append(clbmi)\n", 550 | " X_test[jj]=np.array(valloc)*ti\n", 551 | " \n", 552 | " \n", 553 | " X_train=weightgainfin# Features\n", 554 | " y_train=yr # Labels\n", 555 | " \n", 556 | " \n", 557 | " \n", 558 | " \n", 559 | " #Create a Gaussian Classifier\n", 560 | " clf=RandomForestClassifier(n_estimators=100)\n", 561 | " \n", 562 | " #Train the model using the training sets y_pred=clf.predict(X_test)\n", 563 | " clf.fit(X_train,y_train)\n", 564 | " \n", 565 | " \n", 566 | " X_test2=X_test\n", 567 | " y_pred=clf.predict(X_test)\n", 568 | " \n", 569 | " \n", 570 | " \n", 571 | " print ('SUGGESTED FOOD ITEMS ::')\n", 572 | " for ii in range(len(y_pred)):\n", 573 | " if y_pred[ii]==2:\n", 574 | " print (Food_itemsdata[ii])\n", 575 | " findata=Food_itemsdata[ii]\n", 576 | " if int(veg)==1:\n", 577 | " datanv=['Chicken Burger']\n", 578 | " for it in range(len(datanv)):\n", 579 | " if findata==datanv[it]:\n", 580 | " print('VegNovVeg')\n", 581 | "\n", 582 | " print('\\n Thank You for taking our recommendations. :)')\n", 583 | "\n", 584 | "\n", 585 | "\n", 586 | "def Healthy():\n", 587 | " show_entry_fields()\n", 588 | "\n", 589 | " breakfastfoodseparated=[]\n", 590 | " Lunchfoodseparated=[]\n", 591 | " Dinnerfoodseparated=[]\n", 592 | " \n", 593 | " breakfastfoodseparatedID=[]\n", 594 | " LunchfoodseparatedID=[]\n", 595 | " DinnerfoodseparatedID=[]\n", 596 | " \n", 597 | " for i in range(len(Breakfastdata)):\n", 598 | " if BreakfastdataNumpy[i]==1:\n", 599 | " breakfastfoodseparated.append( Food_itemsdata[i] )\n", 600 | " breakfastfoodseparatedID.append(i)\n", 601 | " if LunchdataNumpy[i]==1:\n", 602 | " Lunchfoodseparated.append(Food_itemsdata[i])\n", 603 | " LunchfoodseparatedID.append(i)\n", 604 | " if DinnerdataNumpy[i]==1:\n", 605 | " Dinnerfoodseparated.append(Food_itemsdata[i])\n", 606 | " DinnerfoodseparatedID.append(i)\n", 607 | " \n", 608 | " # retrieving rows by loc method |\n", 609 | " LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID]\n", 610 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T\n", 611 | " val=list(np.arange(5,15))\n", 612 | " Valapnd=[0]+val\n", 613 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd]\n", 614 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T\n", 615 | " \n", 616 | " # retrieving rows by loc method \n", 617 | " breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID]\n", 618 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T\n", 619 | " val=list(np.arange(5,15))\n", 620 | " Valapnd=[0]+val\n", 621 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd]\n", 622 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T\n", 623 | " \n", 624 | " \n", 625 | " # retrieving rows by loc method \n", 626 | " DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID]\n", 627 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T\n", 628 | " val=list(np.arange(5,15))\n", 629 | " Valapnd=[0]+val\n", 630 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd]\n", 631 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T\n", 632 | " \n", 633 | " \n", 634 | " age=int(e1.get())\n", 635 | " veg=float(e2.get())\n", 636 | " weight=float(e3.get())\n", 637 | " height=float(e4.get())\n", 638 | " bmi = weight/((height/100)**2) \n", 639 | " agewiseinp=0\n", 640 | " \n", 641 | " for lp in range (0,80,20):\n", 642 | " test_list=np.arange(lp,lp+20)\n", 643 | " for i in test_list: \n", 644 | " if(i == age):\n", 645 | " tr=round(lp/20) \n", 646 | " agecl=round(lp/20) \n", 647 | "\n", 648 | " \n", 649 | " #conditions\n", 650 | " print(\"Your body mass index is: \", bmi)\n", 651 | " if ( bmi < 16):\n", 652 | " print(\"Acoording to your BMI, you are Severely Underweight\")\n", 653 | " clbmi=4\n", 654 | " elif ( bmi >= 16 and bmi < 18.5):\n", 655 | " print(\"Acoording to your BMI, you are Underweight\")\n", 656 | " clbmi=3\n", 657 | " elif ( bmi >= 18.5 and bmi < 25):\n", 658 | " print(\"Acoording to your BMI, you are Healthy\")\n", 659 | " clbmi=2\n", 660 | " elif ( bmi >= 25 and bmi < 30):\n", 661 | " print(\"Acoording to your BMI, you are Overweight\")\n", 662 | " clbmi=1\n", 663 | " elif ( bmi >=30):\n", 664 | " print(\"Acoording to your BMI, you are Severely Overweight\")\n", 665 | " clbmi=0\n", 666 | "\n", 667 | " \n", 668 | " DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy()\n", 669 | " LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy()\n", 670 | " breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy()\n", 671 | " ti=(bmi+agecl)/2\n", 672 | " \n", 673 | " \n", 674 | "\n", 675 | " Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)]\n", 676 | " \n", 677 | " X = np.array(Datacalorie)\n", 678 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 679 | " \n", 680 | " XValu=np.arange(0,len(kmeans.labels_))\n", 681 | " # fig,axs=plt.subplots(1,1,figsize=(15,5))\n", 682 | " # plt.bar(XValu,kmeans.labels_)\n", 683 | " dnrlbl=kmeans.labels_\n", 684 | " # plt.title(\"Predicted Low-High Weigted Calorie Foods\")\n", 685 | " \n", 686 | " Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)]\n", 687 | " \n", 688 | " X = np.array(Datacalorie)\n", 689 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 690 | " #print ('## Prediction Result ##')\n", 691 | " #print(kmeans.labels_)\n", 692 | " XValu=np.arange(0,len(kmeans.labels_))\n", 693 | " # fig,axs=plt.subplots(1,1,figsize=(15,5))\n", 694 | " # plt.bar(XValu,kmeans.labels_)\n", 695 | " lnchlbl=kmeans.labels_\n", 696 | " # plt.title(\"Predicted Low-High Weigted Calorie Foods\")\n", 697 | " \n", 698 | " Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)]\n", 699 | " \n", 700 | " X = np.array(Datacalorie)\n", 701 | " kmeans = KMeans(n_clusters=3, random_state=0).fit(X)\n", 702 | " \n", 703 | " XValu=np.arange(0,len(kmeans.labels_))\n", 704 | " # fig,axs=plt.subplots(1,1,figsize=(15,5))\n", 705 | " # plt.bar(XValu,kmeans.labels_)\n", 706 | " brklbl=kmeans.labels_\n", 707 | " # print (len(brklbl))\n", 708 | " # plt.title(\"Predicted Low-High Weigted Calorie Foods\")\n", 709 | " inp=[]\n", 710 | " ## Reading of the Dataet\n", 711 | " datafin=pd.read_csv('nutrition_distriution.csv')\n", 712 | " datafin.head(5)\n", 713 | " \n", 714 | " dataTog=datafin.T\n", 715 | " bmicls=[0,1,2,3,4]\n", 716 | " agecls=[0,1,2,3,4]\n", 717 | " weightlosscat = dataTog.iloc[[1,2,7,8]]\n", 718 | " weightlosscat=weightlosscat.T\n", 719 | " weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]]\n", 720 | " weightgaincat=weightgaincat.T\n", 721 | " healthycat = dataTog.iloc[[1,2,3,4,6,7,9]]\n", 722 | " healthycat=healthycat.T\n", 723 | " weightlosscatDdata=weightlosscat.to_numpy()\n", 724 | " weightgaincatDdata=weightgaincat.to_numpy()\n", 725 | " healthycatDdata=healthycat.to_numpy()\n", 726 | " weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)]\n", 727 | " weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)]\n", 728 | " healthycat=healthycatDdata[1:,0:len(healthycatDdata)]\n", 729 | " \n", 730 | " \n", 731 | " weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32)\n", 732 | " weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32)\n", 733 | " healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32)\n", 734 | " t=0\n", 735 | " r=0\n", 736 | " s=0\n", 737 | " yt=[]\n", 738 | " yr=[]\n", 739 | " ys=[]\n", 740 | " for zz in range(5):\n", 741 | " for jj in range(len(weightlosscat)):\n", 742 | " valloc=list(weightlosscat[jj])\n", 743 | " valloc.append(bmicls[zz])\n", 744 | " valloc.append(agecls[zz])\n", 745 | " weightlossfin[t]=np.array(valloc)\n", 746 | " yt.append(brklbl[jj])\n", 747 | " t+=1\n", 748 | " for jj in range(len(weightgaincat)):\n", 749 | " valloc=list(weightgaincat[jj])\n", 750 | " #print (valloc)\n", 751 | " valloc.append(bmicls[zz])\n", 752 | " valloc.append(agecls[zz])\n", 753 | " weightgainfin[r]=np.array(valloc)\n", 754 | " yr.append(lnchlbl[jj])\n", 755 | " r+=1\n", 756 | " for jj in range(len(healthycat)):\n", 757 | " valloc=list(healthycat[jj])\n", 758 | " valloc.append(bmicls[zz])\n", 759 | " valloc.append(agecls[zz])\n", 760 | " healthycatfin[s]=np.array(valloc)\n", 761 | " ys.append(dnrlbl[jj])\n", 762 | " s+=1\n", 763 | "\n", 764 | " X_test=np.zeros((len(healthycat)*5,9),dtype=np.float32)\n", 765 | " \n", 766 | " for jj in range(len(healthycat)):\n", 767 | " valloc=list(healthycat[jj])\n", 768 | " valloc.append(agecl)\n", 769 | " valloc.append(clbmi)\n", 770 | " X_test[jj]=np.array(valloc)*ti\n", 771 | " \n", 772 | " \n", 773 | " X_train=healthycatfin# Features\n", 774 | " y_train=ys # Labels\n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | " \n", 779 | " #Create a Gaussian Classifier\n", 780 | " clf=RandomForestClassifier(n_estimators=100)\n", 781 | " \n", 782 | " #Train the model using the training sets y_pred=clf.predict(X_test)\n", 783 | " clf.fit(X_train,y_train)\n", 784 | " \n", 785 | " \n", 786 | " X_test2=X_test\n", 787 | " y_pred=clf.predict(X_test)\n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " print ('SUGGESTED FOOD ITEMS ::')\n", 792 | " for ii in range(len(y_pred)):\n", 793 | " if y_pred[ii]==2:\n", 794 | " print (Food_itemsdata[ii])\n", 795 | " findata=Food_itemsdata[ii]\n", 796 | " if int(veg)==1:\n", 797 | " datanv=['Chicken Burger']\n", 798 | "\n", 799 | " print('\\n Thank You for taking our recommendations. :)')\n", 800 | "\n", 801 | "if __name__ == '__main__':\n", 802 | " main_win = Tk()\n", 803 | " \n", 804 | " Label(main_win,text=\"Age\").grid(row=0,column=0,sticky=W,pady=4)\n", 805 | " Label(main_win,text=\"veg/Non veg (1/0)\").grid(row=1,column=0,sticky=W,pady=4)\n", 806 | " Label(main_win,text=\"Weight (in kg)\").grid(row=2,column=0,sticky=W,pady=4)\n", 807 | " Label(main_win,text=\"Height (in cm)\").grid(row=3,column=0,sticky=W,pady=4)\n", 808 | "\n", 809 | " e1 = Entry(main_win)\n", 810 | " e2 = Entry(main_win)\n", 811 | " e3 = Entry(main_win)\n", 812 | " e4 = Entry(main_win)\n", 813 | "\n", 814 | " e1.grid(row=0, column=1)\n", 815 | " e2.grid(row=1, column=1)\n", 816 | " e3.grid(row=2, column=1)\n", 817 | " e4.grid(row=3, column=1)\n", 818 | "\n", 819 | " Button(main_win,text='Quit',command=main_win.quit).grid(row=5,column=0,sticky=W,pady=4)\n", 820 | " Button(main_win,text='Weight Loss',command=Weight_Loss).grid(row=1,column=4,sticky=W,pady=4)\n", 821 | " Button(main_win,text='Weight Gain',command=Weight_Gain).grid(row=2,column=4,sticky=W,pady=4)\n", 822 | " Button(main_win,text='Healthy',command=Healthy).grid(row=3,column=4,sticky=W,pady=4)\n", 823 | " main_win.geometry(\"400x200\")\n", 824 | " main_win.wm_title(\"DIET RECOMMENDATION SYSTEM\")\n", 825 | "\n", 826 | " main_win.mainloop()\n" 827 | ] 828 | }, 829 | { 830 | "cell_type": "code", 831 | "execution_count": 2, 832 | "metadata": {}, 833 | "outputs": [], 834 | "source": [ 835 | "from tkinter import *\n", 836 | "\n", 837 | "win = Tk()\n", 838 | "win.geometry(\"400x200\")\n", 839 | "win.wm_title(\"xcv\")\n", 840 | "Button(win,text='Quit',command=win.quit).grid(row=5,column=0,sticky=W,pady=4)\n", 841 | "win.mainloop()" 842 | ] 843 | }, 844 | { 845 | "cell_type": "code", 846 | "execution_count": null, 847 | "metadata": {}, 848 | "outputs": [], 849 | "source": [] 850 | } 851 | ], 852 | "metadata": { 853 | "kernelspec": { 854 | "display_name": "Python 3", 855 | "language": "python", 856 | "name": "python3" 857 | }, 858 | "language_info": { 859 | "codemirror_mode": { 860 | "name": "ipython", 861 | "version": 3 862 | }, 863 | "file_extension": ".py", 864 | "mimetype": "text/x-python", 865 | "name": "python", 866 | "nbconvert_exporter": "python", 867 | "pygments_lexer": "ipython3", 868 | "version": "3.7.2" 869 | } 870 | }, 871 | "nbformat": 4, 872 | "nbformat_minor": 2 873 | } 874 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KBES_Project-11615139_K1637_B35 2 | A Diet Recommendation System using Machine Learning Algorithms. 3 | To run the project prerequirements are: 4 | Install the following by running the command: 5 | pip install pandas 6 | pip install numpy 7 | pip install tkinter 8 | pip install sklearn 9 | pip install jupyterlabs 10 | 11 | if already installed then ignore 12 | 13 | Type "jupyter notebook" on command prompt and then open the ".ipynb" extension file or run "python diet_recommender.py" on cmd. 14 | -------------------------------------------------------------------------------- /diet_recommender.py: -------------------------------------------------------------------------------- 1 | import os 2 | import psutil 3 | import time 4 | import subprocess 5 | import fnmatch 6 | import pandas as pd 7 | import numpy as np 8 | import seaborn as sns 9 | import matplotlib.pyplot as plt 10 | from tkinter import * 11 | from PIL import ImageFilter,Image 12 | from tkinter import filedialog, messagebox 13 | from sklearn.cluster import KMeans 14 | from sklearn.model_selection import train_test_split 15 | from sklearn.ensemble import RandomForestClassifier 16 | 17 | data=pd.read_csv('food.csv') 18 | Breakfastdata=data['Breakfast'] 19 | BreakfastdataNumpy=Breakfastdata.to_numpy() 20 | 21 | Lunchdata=data['Lunch'] 22 | LunchdataNumpy=Lunchdata.to_numpy() 23 | 24 | Dinnerdata=data['Dinner'] 25 | DinnerdataNumpy=Dinnerdata.to_numpy() 26 | Food_itemsdata=data['Food_items'] 27 | 28 | 29 | 30 | def show_entry_fields(): 31 | print("\n Age: %s\n Veg-NonVeg: %s\n Weight: %s kg\n Hight: %s cm\n" % (e1.get(), e2.get(),e3.get(), e4.get())) 32 | 33 | 34 | def Weight_Loss(): 35 | show_entry_fields() 36 | 37 | breakfastfoodseparated=[] 38 | Lunchfoodseparated=[] 39 | Dinnerfoodseparated=[] 40 | 41 | breakfastfoodseparatedID=[] 42 | LunchfoodseparatedID=[] 43 | DinnerfoodseparatedID=[] 44 | 45 | for i in range(len(Breakfastdata)): 46 | if BreakfastdataNumpy[i]==1: 47 | breakfastfoodseparated.append( Food_itemsdata[i] ) 48 | breakfastfoodseparatedID.append(i) 49 | if LunchdataNumpy[i]==1: 50 | Lunchfoodseparated.append(Food_itemsdata[i]) 51 | LunchfoodseparatedID.append(i) 52 | if DinnerdataNumpy[i]==1: 53 | Dinnerfoodseparated.append(Food_itemsdata[i]) 54 | DinnerfoodseparatedID.append(i) 55 | 56 | # retrieving Lunch data rows by loc method | 57 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 58 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 59 | #print(LunchfoodseparatedIDdata) 60 | val=list(np.arange(5,15)) 61 | Valapnd=[0]+val 62 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 63 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 64 | #print(LunchfoodseparatedIDdata) 65 | 66 | # retrieving Breafast data rows by loc method 67 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 68 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 69 | val=list(np.arange(5,15)) 70 | Valapnd=[0]+val 71 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 72 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 73 | 74 | 75 | # retrieving Dinner Data rows by loc method 76 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 77 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 78 | val=list(np.arange(5,15)) 79 | Valapnd=[0]+val 80 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 81 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 82 | 83 | #calculating BMI 84 | age=int(e1.get()) 85 | veg=float(e2.get()) 86 | weight=float(e3.get()) 87 | height=float(e4.get()) 88 | bmi = weight/((height/100)**2) 89 | agewiseinp=0 90 | 91 | for lp in range (0,80,20): 92 | test_list=np.arange(lp,lp+20) 93 | for i in test_list: 94 | if(i == age): 95 | tr=round(lp/20) 96 | agecl=round(lp/20) 97 | 98 | 99 | #conditions 100 | print("Your body mass index is: ", bmi) 101 | if ( bmi < 16): 102 | print("Acoording to your BMI, you are Severely Underweight") 103 | clbmi=4 104 | elif ( bmi >= 16 and bmi < 18.5): 105 | print("Acoording to your BMI, you are Underweight") 106 | clbmi=3 107 | elif ( bmi >= 18.5 and bmi < 25): 108 | print("Acoording to your BMI, you are Healthy") 109 | clbmi=2 110 | elif ( bmi >= 25 and bmi < 30): 111 | print("Acoording to your BMI, you are Overweight") 112 | clbmi=1 113 | elif ( bmi >=30): 114 | print("Acoording to your BMI, you are Severely Overweight") 115 | clbmi=0 116 | 117 | #converting into numpy array 118 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 119 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 120 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 121 | ti=(clbmi+agecl)/2 122 | 123 | ## K-Means Based Dinner Food 124 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 125 | 126 | X = np.array(Datacalorie) 127 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 128 | 129 | XValu=np.arange(0,len(kmeans.labels_)) 130 | 131 | # retrieving the labels for dinner food 132 | dnrlbl=kmeans.labels_ 133 | 134 | ## K-Means Based lunch Food 135 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 136 | 137 | X = np.array(Datacalorie) 138 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 139 | 140 | XValu=np.arange(0,len(kmeans.labels_)) 141 | 142 | # retrieving the labels for lunch food 143 | lnchlbl=kmeans.labels_ 144 | 145 | ## K-Means Based lunch Food 146 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 147 | 148 | X = np.array(Datacalorie) 149 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 150 | 151 | XValu=np.arange(0,len(kmeans.labels_)) 152 | 153 | # retrieving the labels for breakfast food 154 | brklbl=kmeans.labels_ 155 | 156 | inp=[] 157 | ## Reading of the Dataet 158 | datafin=pd.read_csv('nutrition_distriution.csv') 159 | 160 | ## train set 161 | dataTog=datafin.T 162 | bmicls=[0,1,2,3,4] 163 | agecls=[0,1,2,3,4] 164 | weightlosscat = dataTog.iloc[[1,2,7,8]] 165 | weightlosscat=weightlosscat.T 166 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 167 | weightgaincat=weightgaincat.T 168 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 169 | healthycat=healthycat.T 170 | weightlosscatDdata=weightlosscat.to_numpy() 171 | weightgaincatDdata=weightgaincat.to_numpy() 172 | healthycatDdata=healthycat.to_numpy() 173 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 174 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 175 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 176 | 177 | 178 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 179 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 180 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 181 | t=0 182 | r=0 183 | s=0 184 | yt=[] 185 | yr=[] 186 | ys=[] 187 | for zz in range(5): 188 | for jj in range(len(weightlosscat)): 189 | valloc=list(weightlosscat[jj]) 190 | valloc.append(bmicls[zz]) 191 | valloc.append(agecls[zz]) 192 | weightlossfin[t]=np.array(valloc) 193 | yt.append(brklbl[jj]) 194 | t+=1 195 | for jj in range(len(weightgaincat)): 196 | valloc=list(weightgaincat[jj]) 197 | valloc.append(bmicls[zz]) 198 | valloc.append(agecls[zz]) 199 | weightgainfin[r]=np.array(valloc) 200 | yr.append(lnchlbl[jj]) 201 | r+=1 202 | for jj in range(len(healthycat)): 203 | valloc=list(healthycat[jj]) 204 | valloc.append(bmicls[zz]) 205 | valloc.append(agecls[zz]) 206 | healthycatfin[s]=np.array(valloc) 207 | ys.append(dnrlbl[jj]) 208 | s+=1 209 | 210 | 211 | X_test=np.zeros((len(weightlosscat),6),dtype=np.float32) 212 | 213 | print('####################') 214 | 215 | #randomforest 216 | for jj in range(len(weightlosscat)): 217 | valloc=list(weightlosscat[jj]) 218 | valloc.append(agecl) 219 | valloc.append(clbmi) 220 | X_test[jj]=np.array(valloc)*ti 221 | 222 | 223 | 224 | X_train=weightlossfin# Features 225 | y_train=yt # Labels 226 | 227 | #Create a Gaussian Classifier 228 | clf=RandomForestClassifier(n_estimators=100) 229 | 230 | #Train the model using the training sets y_pred=clf.predict(X_test) 231 | clf.fit(X_train,y_train) 232 | 233 | #print (X_test[1]) 234 | X_test2=X_test 235 | y_pred=clf.predict(X_test) 236 | 237 | 238 | print ('SUGGESTED FOOD ITEMS ::') 239 | for ii in range(len(y_pred)): 240 | if y_pred[ii]==2: #weightloss 241 | print (Food_itemsdata[ii]) 242 | findata=Food_itemsdata[ii] 243 | if int(veg)==1: 244 | datanv=['Chicken Burger'] 245 | for it in range(len(datanv)): 246 | if findata==datanv[it]: 247 | print('VegNovVeg') 248 | 249 | print('\n Thank You for taking our recommendations. :)') 250 | 251 | 252 | 253 | 254 | def Weight_Gain(): 255 | show_entry_fields() 256 | 257 | breakfastfoodseparated=[] 258 | Lunchfoodseparated=[] 259 | Dinnerfoodseparated=[] 260 | 261 | breakfastfoodseparatedID=[] 262 | LunchfoodseparatedID=[] 263 | DinnerfoodseparatedID=[] 264 | 265 | for i in range(len(Breakfastdata)): 266 | if BreakfastdataNumpy[i]==1: 267 | breakfastfoodseparated.append( Food_itemsdata[i] ) 268 | breakfastfoodseparatedID.append(i) 269 | if LunchdataNumpy[i]==1: 270 | Lunchfoodseparated.append(Food_itemsdata[i]) 271 | LunchfoodseparatedID.append(i) 272 | if DinnerdataNumpy[i]==1: 273 | Dinnerfoodseparated.append(Food_itemsdata[i]) 274 | DinnerfoodseparatedID.append(i) 275 | 276 | # retrieving rows by loc method | 277 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 278 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 279 | val=list(np.arange(5,15)) 280 | Valapnd=[0]+val 281 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 282 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 283 | 284 | # retrieving rows by loc method 285 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 286 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 287 | val=list(np.arange(5,15)) 288 | Valapnd=[0]+val 289 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 290 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 291 | 292 | 293 | # retrieving rows by loc method 294 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 295 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 296 | val=list(np.arange(5,15)) 297 | Valapnd=[0]+val 298 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 299 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 300 | 301 | #claculating BMI 302 | age=int(e1.get()) 303 | veg=float(e2.get()) 304 | weight=float(e3.get()) 305 | height=float(e4.get()) 306 | bmi = weight/((height/100)**2) 307 | 308 | for lp in range (0,80,20): 309 | test_list=np.arange(lp,lp+20) 310 | for i in test_list: 311 | if(i == age): 312 | tr=round(lp/20) 313 | agecl=round(lp/20) 314 | 315 | print("Your body mass index is: ", bmi) 316 | if ( bmi < 16): 317 | print("Acoording to your BMI, you are Severely Underweight") 318 | clbmi=4 319 | elif ( bmi >= 16 and bmi < 18.5): 320 | print("Acoording to your BMI, you are Underweight") 321 | clbmi=3 322 | elif ( bmi >= 18.5 and bmi < 25): 323 | print("Acoording to your BMI, you are Healthy") 324 | clbmi=2 325 | elif ( bmi >= 25 and bmi < 30): 326 | print("Acoording to your BMI, you are Overweight") 327 | clbmi=1 328 | elif ( bmi >=30): 329 | print("Acoording to your BMI, you are Severely Overweight") 330 | clbmi=0 331 | 332 | 333 | 334 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 335 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 336 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 337 | ti=(bmi+agecl)/2 338 | 339 | 340 | ## K-Means Based Dinner Food 341 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 342 | 343 | X = np.array(Datacalorie) 344 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 345 | 346 | XValu=np.arange(0,len(kmeans.labels_)) 347 | # plt.bar(XValu,kmeans.labels_) 348 | dnrlbl=kmeans.labels_ 349 | # plt.title("Predicted Low-High Weigted Calorie Foods") 350 | 351 | ## K-Means Based lunch Food 352 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 353 | 354 | X = np.array(Datacalorie) 355 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 356 | 357 | XValu=np.arange(0,len(kmeans.labels_)) 358 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 359 | # plt.bar(XValu,kmeans.labels_) 360 | lnchlbl=kmeans.labels_ 361 | # plt.title("Predicted Low-High Weigted Calorie Foods") 362 | 363 | ## K-Means Based lunch Food 364 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 365 | 366 | X = np.array(Datacalorie) 367 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 368 | 369 | XValu=np.arange(0,len(kmeans.labels_)) 370 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 371 | # plt.bar(XValu,kmeans.labels_) 372 | brklbl=kmeans.labels_ 373 | 374 | # plt.title("Predicted Low-High Weigted Calorie Foods") 375 | inp=[] 376 | ## Reading of the Dataet 377 | datafin=pd.read_csv('nutrition_distriution.csv') 378 | datafin.head(5) 379 | 380 | dataTog=datafin.T 381 | bmicls=[0,1,2,3,4] 382 | agecls=[0,1,2,3,4] 383 | weightlosscat = dataTog.iloc[[1,2,7,8]] 384 | weightlosscat=weightlosscat.T 385 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 386 | weightgaincat=weightgaincat.T 387 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 388 | healthycat=healthycat.T 389 | weightlosscatDdata=weightlosscat.to_numpy() 390 | weightgaincatDdata=weightgaincat.to_numpy() 391 | healthycatDdata=healthycat.to_numpy() 392 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 393 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 394 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 395 | 396 | 397 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 398 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 399 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 400 | t=0 401 | r=0 402 | s=0 403 | yt=[] 404 | yr=[] 405 | ys=[] 406 | for zz in range(5): 407 | for jj in range(len(weightlosscat)): 408 | valloc=list(weightlosscat[jj]) 409 | valloc.append(bmicls[zz]) 410 | valloc.append(agecls[zz]) 411 | weightlossfin[t]=np.array(valloc) 412 | yt.append(brklbl[jj]) 413 | t+=1 414 | for jj in range(len(weightgaincat)): 415 | valloc=list(weightgaincat[jj]) 416 | #print (valloc) 417 | valloc.append(bmicls[zz]) 418 | valloc.append(agecls[zz]) 419 | weightgainfin[r]=np.array(valloc) 420 | yr.append(lnchlbl[jj]) 421 | r+=1 422 | for jj in range(len(healthycat)): 423 | valloc=list(healthycat[jj]) 424 | valloc.append(bmicls[zz]) 425 | valloc.append(agecls[zz]) 426 | healthycatfin[s]=np.array(valloc) 427 | ys.append(dnrlbl[jj]) 428 | s+=1 429 | 430 | 431 | X_test=np.zeros((len(weightgaincat),10),dtype=np.float32) 432 | 433 | print('####################') 434 | # In[287]: 435 | for jj in range(len(weightgaincat)): 436 | valloc=list(weightgaincat[jj]) 437 | valloc.append(agecl) 438 | valloc.append(clbmi) 439 | X_test[jj]=np.array(valloc)*ti 440 | 441 | 442 | X_train=weightgainfin# Features 443 | y_train=yr # Labels 444 | 445 | 446 | 447 | 448 | #Create a Gaussian Classifier 449 | clf=RandomForestClassifier(n_estimators=100) 450 | 451 | #Train the model using the training sets y_pred=clf.predict(X_test) 452 | clf.fit(X_train,y_train) 453 | 454 | 455 | X_test2=X_test 456 | y_pred=clf.predict(X_test) 457 | 458 | 459 | 460 | print ('SUGGESTED FOOD ITEMS ::') 461 | for ii in range(len(y_pred)): 462 | if y_pred[ii]==2: 463 | print (Food_itemsdata[ii]) 464 | findata=Food_itemsdata[ii] 465 | if int(veg)==1: 466 | datanv=['Chicken Burger'] 467 | for it in range(len(datanv)): 468 | if findata==datanv[it]: 469 | print('VegNovVeg') 470 | 471 | print('\n Thank You for taking our recommendations. :)') 472 | 473 | 474 | 475 | def Healthy(): 476 | show_entry_fields() 477 | 478 | breakfastfoodseparated=[] 479 | Lunchfoodseparated=[] 480 | Dinnerfoodseparated=[] 481 | 482 | breakfastfoodseparatedID=[] 483 | LunchfoodseparatedID=[] 484 | DinnerfoodseparatedID=[] 485 | 486 | for i in range(len(Breakfastdata)): 487 | if BreakfastdataNumpy[i]==1: 488 | breakfastfoodseparated.append( Food_itemsdata[i] ) 489 | breakfastfoodseparatedID.append(i) 490 | if LunchdataNumpy[i]==1: 491 | Lunchfoodseparated.append(Food_itemsdata[i]) 492 | LunchfoodseparatedID.append(i) 493 | if DinnerdataNumpy[i]==1: 494 | Dinnerfoodseparated.append(Food_itemsdata[i]) 495 | DinnerfoodseparatedID.append(i) 496 | 497 | # retrieving rows by loc method | 498 | LunchfoodseparatedIDdata = data.iloc[LunchfoodseparatedID] 499 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 500 | val=list(np.arange(5,15)) 501 | Valapnd=[0]+val 502 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.iloc[Valapnd] 503 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.T 504 | 505 | # retrieving rows by loc method 506 | breakfastfoodseparatedIDdata = data.iloc[breakfastfoodseparatedID] 507 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 508 | val=list(np.arange(5,15)) 509 | Valapnd=[0]+val 510 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.iloc[Valapnd] 511 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.T 512 | 513 | 514 | # retrieving rows by loc method 515 | DinnerfoodseparatedIDdata = data.iloc[DinnerfoodseparatedID] 516 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 517 | val=list(np.arange(5,15)) 518 | Valapnd=[0]+val 519 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.iloc[Valapnd] 520 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.T 521 | 522 | 523 | age=int(e1.get()) 524 | veg=float(e2.get()) 525 | weight=float(e3.get()) 526 | height=float(e4.get()) 527 | bmi = weight/((height/100)**2) 528 | agewiseinp=0 529 | 530 | for lp in range (0,80,20): 531 | test_list=np.arange(lp,lp+20) 532 | for i in test_list: 533 | if(i == age): 534 | tr=round(lp/20) 535 | agecl=round(lp/20) 536 | 537 | 538 | #conditions 539 | print("Your body mass index is: ", bmi) 540 | if ( bmi < 16): 541 | print("Acoording to your BMI, you are Severely Underweight") 542 | clbmi=4 543 | elif ( bmi >= 16 and bmi < 18.5): 544 | print("Acoording to your BMI, you are Underweight") 545 | clbmi=3 546 | elif ( bmi >= 18.5 and bmi < 25): 547 | print("Acoording to your BMI, you are Healthy") 548 | clbmi=2 549 | elif ( bmi >= 25 and bmi < 30): 550 | print("Acoording to your BMI, you are Overweight") 551 | clbmi=1 552 | elif ( bmi >=30): 553 | print("Acoording to your BMI, you are Severely Overweight") 554 | clbmi=0 555 | 556 | 557 | DinnerfoodseparatedIDdata=DinnerfoodseparatedIDdata.to_numpy() 558 | LunchfoodseparatedIDdata=LunchfoodseparatedIDdata.to_numpy() 559 | breakfastfoodseparatedIDdata=breakfastfoodseparatedIDdata.to_numpy() 560 | ti=(bmi+agecl)/2 561 | 562 | 563 | 564 | Datacalorie=DinnerfoodseparatedIDdata[1:,1:len(DinnerfoodseparatedIDdata)] 565 | 566 | X = np.array(Datacalorie) 567 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 568 | 569 | XValu=np.arange(0,len(kmeans.labels_)) 570 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 571 | # plt.bar(XValu,kmeans.labels_) 572 | dnrlbl=kmeans.labels_ 573 | # plt.title("Predicted Low-High Weigted Calorie Foods") 574 | 575 | Datacalorie=LunchfoodseparatedIDdata[1:,1:len(LunchfoodseparatedIDdata)] 576 | 577 | X = np.array(Datacalorie) 578 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 579 | #print ('## Prediction Result ##') 580 | #print(kmeans.labels_) 581 | XValu=np.arange(0,len(kmeans.labels_)) 582 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 583 | # plt.bar(XValu,kmeans.labels_) 584 | lnchlbl=kmeans.labels_ 585 | # plt.title("Predicted Low-High Weigted Calorie Foods") 586 | 587 | Datacalorie=breakfastfoodseparatedIDdata[1:,1:len(breakfastfoodseparatedIDdata)] 588 | 589 | X = np.array(Datacalorie) 590 | kmeans = KMeans(n_clusters=3, random_state=0).fit(X) 591 | 592 | XValu=np.arange(0,len(kmeans.labels_)) 593 | # fig,axs=plt.subplots(1,1,figsize=(15,5)) 594 | # plt.bar(XValu,kmeans.labels_) 595 | brklbl=kmeans.labels_ 596 | # print (len(brklbl)) 597 | # plt.title("Predicted Low-High Weigted Calorie Foods") 598 | inp=[] 599 | ## Reading of the Dataet 600 | datafin=pd.read_csv('nutrition_distriution.csv') 601 | datafin.head(5) 602 | 603 | dataTog=datafin.T 604 | bmicls=[0,1,2,3,4] 605 | agecls=[0,1,2,3,4] 606 | weightlosscat = dataTog.iloc[[1,2,7,8]] 607 | weightlosscat=weightlosscat.T 608 | weightgaincat= dataTog.iloc[[0,1,2,3,4,7,9,10]] 609 | weightgaincat=weightgaincat.T 610 | healthycat = dataTog.iloc[[1,2,3,4,6,7,9]] 611 | healthycat=healthycat.T 612 | weightlosscatDdata=weightlosscat.to_numpy() 613 | weightgaincatDdata=weightgaincat.to_numpy() 614 | healthycatDdata=healthycat.to_numpy() 615 | weightlosscat=weightlosscatDdata[1:,0:len(weightlosscatDdata)] 616 | weightgaincat=weightgaincatDdata[1:,0:len(weightgaincatDdata)] 617 | healthycat=healthycatDdata[1:,0:len(healthycatDdata)] 618 | 619 | 620 | weightlossfin=np.zeros((len(weightlosscat)*5,6),dtype=np.float32) 621 | weightgainfin=np.zeros((len(weightgaincat)*5,10),dtype=np.float32) 622 | healthycatfin=np.zeros((len(healthycat)*5,9),dtype=np.float32) 623 | t=0 624 | r=0 625 | s=0 626 | yt=[] 627 | yr=[] 628 | ys=[] 629 | for zz in range(5): 630 | for jj in range(len(weightlosscat)): 631 | valloc=list(weightlosscat[jj]) 632 | valloc.append(bmicls[zz]) 633 | valloc.append(agecls[zz]) 634 | weightlossfin[t]=np.array(valloc) 635 | yt.append(brklbl[jj]) 636 | t+=1 637 | for jj in range(len(weightgaincat)): 638 | valloc=list(weightgaincat[jj]) 639 | #print (valloc) 640 | valloc.append(bmicls[zz]) 641 | valloc.append(agecls[zz]) 642 | weightgainfin[r]=np.array(valloc) 643 | yr.append(lnchlbl[jj]) 644 | r+=1 645 | for jj in range(len(healthycat)): 646 | valloc=list(healthycat[jj]) 647 | valloc.append(bmicls[zz]) 648 | valloc.append(agecls[zz]) 649 | healthycatfin[s]=np.array(valloc) 650 | ys.append(dnrlbl[jj]) 651 | s+=1 652 | 653 | X_test=np.zeros((len(healthycat)*5,9),dtype=np.float32) 654 | 655 | for jj in range(len(healthycat)): 656 | valloc=list(healthycat[jj]) 657 | valloc.append(agecl) 658 | valloc.append(clbmi) 659 | X_test[jj]=np.array(valloc)*ti 660 | 661 | 662 | X_train=healthycatfin# Features 663 | y_train=ys # Labels 664 | 665 | 666 | 667 | 668 | #Create a Gaussian Classifier 669 | clf=RandomForestClassifier(n_estimators=100) 670 | 671 | #Train the model using the training sets y_pred=clf.predict(X_test) 672 | clf.fit(X_train,y_train) 673 | 674 | 675 | X_test2=X_test 676 | y_pred=clf.predict(X_test) 677 | 678 | 679 | 680 | print ('SUGGESTED FOOD ITEMS ::') 681 | for ii in range(len(y_pred)): 682 | if y_pred[ii]==2: 683 | print (Food_itemsdata[ii]) 684 | findata=Food_itemsdata[ii] 685 | if int(veg)==1: 686 | datanv=['Chicken Burger'] 687 | 688 | print('\n Thank You for taking our recommendations. :)') 689 | 690 | if __name__ == '__main__': 691 | main_win = Tk() 692 | 693 | Label(main_win,text="Age").grid(row=0,column=0,sticky=W,pady=4) 694 | Label(main_win,text="veg/Non veg (1/0)").grid(row=1,column=0,sticky=W,pady=4) 695 | Label(main_win,text="Weight (in kg)").grid(row=2,column=0,sticky=W,pady=4) 696 | Label(main_win,text="Height (in cm)").grid(row=3,column=0,sticky=W,pady=4) 697 | 698 | e1 = Entry(main_win) 699 | e2 = Entry(main_win) 700 | e3 = Entry(main_win) 701 | e4 = Entry(main_win) 702 | 703 | e1.grid(row=0, column=1) 704 | e2.grid(row=1, column=1) 705 | e3.grid(row=2, column=1) 706 | e4.grid(row=3, column=1) 707 | 708 | Button(main_win,text='Quit',command=main_win.quit).grid(row=5,column=0,sticky=W,pady=4) 709 | Button(main_win,text='Weight Loss',command=Weight_Loss).grid(row=1,column=4,sticky=W,pady=4) 710 | Button(main_win,text='Weight Gain',command=Weight_Gain).grid(row=2,column=4,sticky=W,pady=4) 711 | Button(main_win,text='Healthy',command=Healthy).grid(row=3,column=4,sticky=W,pady=4) 712 | main_win.geometry("400x200") 713 | main_win.wm_title("DIET RECOMMENDATION SYSTEM") 714 | 715 | main_win.mainloop() 716 | -------------------------------------------------------------------------------- /food.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 | -------------------------------------------------------------------------------- /nutrition_distriution.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 | --------------------------------------------------------------------------------