### Execute Recommendation Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Example usage of the recommendation function with a test input. ```python test_input=extracted_data.iloc[0:1,6:15].to_numpy() recommand(dataset,test_input,max_list) ``` -------------------------------- ### Run NutriMind with Docker Compose Source: https://github.com/zakaria-narjis/nutrimind/blob/main/README.md Commands to clone the repository and start the application using Docker Compose. ```bash git clone https://github.com/zakaria-narjis/nutrimind cd nutrimind docker compose pull docker compose up -d ``` ```bash git clone https://github.com/zakaria-narjis/nutrimind cd nutrimind docker compose up --build -d ``` -------------------------------- ### POST /generate-meal-plan/ Request Body Source: https://github.com/zakaria-narjis/nutrimind/blob/main/README.md Example JSON payload for generating a daily meal plan based on user health metrics. ```json { "age": 28, "height": 175, "weight": 70, "gender": "Male", "activity": "Moderate exercise (3-5 days/wk)", "number_of_meals": 3, "weight_loss": "Maintain weight" } ``` -------------------------------- ### POST /predict/ Request Body Source: https://github.com/zakaria-narjis/nutrimind/blob/main/README.md Example JSON payload for finding recipes based on a nutrition vector and ingredient filters. ```json { "nutrition_input": [500, 20, 3, 50, 800, 60, 8, 5, 30], "ingredients": ["chicken", "garlic"], "params": {"n_neighbors": 5, "return_distance": false} } ``` -------------------------------- ### Displaying Recipe Dataset Sample Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb A raw output showing the structure of the recipe dataframe including nutritional information and preparation times. ```text Result: RecipeId Name CookTime \ 0 38 Low-Fat Berry Blue Frozen Dessert PT24H 463750 480841 Mango Salsa PT5M 485171 503065 Glazed Pineapple With Cinnamon Creme Fraiche PT10M 158110 165636 Lemon Float Punch PT120H 28595 32172 L & B's Concoction PT5M 224062 233508 Blueberry Mango Smoothie NaN 206883 215824 Blueberry Orange Smoothie NaN 419537 434977 Preserved Apple Pie Filling PT30M 367808 381181 Tropical Twister Smoothies NaN 462235 479288 Summer Fruit Bowl NaN PrepTime TotalTime RecipeIngredientParts \ 0 PT45M PT24H45M c("blueberries", "granulated sugar", "vanilla ... 463750 PT10M PT15M c("fresh mango", "tomatoes", "sweet onion", "f... 485171 PT10M PT20M c("lime", "honey", "ground cinnamon", "ground ... 158110 PT5M PT120H5M c("lemons", "sugar", "water", "ginger ale", "l... 28595 PT5M PT10M c("strawberry", "strawberry", "milk", "blueber... 224062 PT5M PT5M c("vanilla-flavored soymilk", "frozen blueberr... 206883 PT5M PT5M c("blueberries", "fresh blueberries") 419537 PT1H PT1H30M c("apples", "bottled lemon juice", "sugar", "g... 367808 PT5M PT5M c("fresh mango", "papaya", "fresh pineapple ch... 462235 PT1H30M PT1H30M c("blueberries", "granulated sugar", "kirsch",... Calories FatContent SaturatedFatContent CholesterolContent \ 0 170.9 2.5 1.3 8.0 463750 152.5 0.8 0.2 0.0 485171 172.5 2.2 1.2 5.0 158110 158.4 1.7 0.9 0.4 28595 167.3 2.0 1.0 5.7 224062 147.5 0.4 0.1 0.0 206883 179.4 2.6 1.3 0.7 419537 161.3 0.3 0.1 0.0 367808 190.8 2.6 1.4 8.0 462235 155.4 0.2 0.0 0.0 SodiumContent CarbohydrateContent FiberContent SugarContent \ 0 29.8 37.1 3.6 30.2 463750 6.6 37.9 3.8 34.0 485171 19.8 41.5 3.8 32.4 158110 38.6 40.1 4.0 31.1 28595 26.2 38.4 3.0 29.9 224062 2.9 39.5 4.2 34.9 206883 34.3 38.1 3.0 30.4 419537 3.6 42.2 3.8 36.4 367808 32.4 41.3 3.6 29.6 462235 10.2 40.6 3.8 36.2 ProteinContent RecipeInstructions 0 3.2 c("Toss 2 cups berries with sugar.", "Let stan... 463750 2.2 c("In a medium-sized bowl, whisk together vine... 485171 1.4 c("Mix the lime juice and half the lime zest w... 158110 1.9 c("Combine lemon juice and sugar; stir to diss... 28595 3.1 c("Blend the frozen strawberries, ice cubes, y... 224062 0.9 "Place all ingredients in a blender. Blend un... 206883 3.1 c("Combine first 5 ingredients in blender.", "... 419537 0.4 c("Set a large pot of water to boil.", "Pour 1... 367808 4.0 c("Combine all ingredients in a blender and pr... 462235 1.7 c("Place fruit in a large bowl.", "Add sugar a... ``` -------------------------------- ### Display Data Preview Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Displays the first five rows of the loaded recipes dataset. ```python data.head() ``` -------------------------------- ### Initialize Nearest Neighbors Model Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Configure the NearestNeighbors model using cosine similarity and brute-force algorithm. ```python from sklearn.neighbors import NearestNeighbors neigh = NearestNeighbors(metric='cosine',algorithm='brute') neigh.fit(prep_data) ``` -------------------------------- ### Display Recipe Dataset Sample Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Displays the structure and content of the recipe dataframe, including nutritional information and preparation times. ```text Result: RecipeId Name CookTime \ 3 41 Carina's Tofu-Vegetable Kebabs PT20M 7 45 Buttermilk Pie With Gingersnap Crumb Crust PT50M 12 50 Biscotti Di Prato PT50M 18 56 Buttermilk Pie PT1H 22 60 Blueberry Dessert NaN ... ... ... ... 522484 541351 Spinach & Mushroom Quiche with Boursin PT1H 522490 541357 Chocolate Rum Snowballs PT8M 522500 541367 Thick Peanut Pancakes PT10M 522510 541377 Slow-Cooker Classic Coffee Cake PT3H 522512 541379 Meg's Fresh Ginger Gingerbread PT35M PrepTime TotalTime RecipeIngredientParts \ 3 PT24H PT24H20M c("extra firm tofu", "eggplant", "zucchini", "... 7 PT30M PT1H20M c("sugar", "margarine", "egg", "flour", "salt"... 12 PT20M PT1H10M c("flour", "sugar", "baking powder", "salt", "... 18 PT20M PT1H20M c("butter", "margarine", "sugar", "flour", "eg... 22 PT35M PT35M c("Bisquick baking mix", "sugar", "butter", "m... ... ... ... ... 522484 PT20M PT1H20M c("butter", "onion", "sweet pepper", "carrots"... 522490 PT15M PT23M c("rolled oats", "sweetened flaked coconut", "... 522500 PT45M PT55M c("plain flour", "baking powder", "baking soda... 522510 PT20M PT3H20M c("all-purpose flour", "brown sugar", "butter"... 522512 PT1H PT1H35M c("fresh ginger", "unsalted butter", "dark bro... Calories FatContent SaturatedFatContent CholesterolContent \ 3 536.1 24.0 3.8 0.0 7 228.0 7.1 1.7 24.5 12 89.4 2.6 0.3 16.6 18 395.9 19.1 9.8 101.5 22 381.1 17.3 8.8 62.1 ... ... ... ... ... 522484 197.6 11.0 4.0 82.2 522490 127.8 6.2 4.1 14.9 522500 712.9 25.4 8.6 121.4 522510 358.9 19.8 10.5 103.1 522512 316.6 12.5 7.6 54.4 SodiumContent CarbohydrateContent FiberContent SugarContent \ 3 1558.6 64.2 17.3 32.1 7 281.8 37.5 0.5 24.7 12 23.5 14.5 0.8 7.3 18 269.8 52.2 0.7 39.9 22 437.6 54.5 1.6 36.9 ... ... ... ... ... 522484 283.3 19.0 2.0 3.0 522490 57.9 15.8 1.3 9.4 522500 503.9 100.3 6.0 20.2 522510 323.4 41.5 0.8 24.8 522512 278.2 48.5 0.8 22.8 ProteinContent RecipeInstructions 3 29.3 c("Drain the tofu, carefully squeezing out exc... 7 4.2 c("Preheat oven to 350°F.", "Make pie crust, u... 12 2.3 c("EGG WASH 1 Egg, large 1 tsp Water In the bo... 18 5.0 c("Preheat oven to 400°F.", "Beat the butter a... 22 3.9 c("Heat oven to 400 degrees.", "Mix 2 cups bak... ... ... ... 522484 6.1 c("Bake pie crust(s) according to package inst... 522490 1.8 c("In a large mixing bowl, combine oats, 1 cup... 522500 23.2 c("Add rock sugar to milk.", "Steam milk at lo... 522510 4.8 c("Line bottom and sides of 5-quart oval slow ... 522512 3.9 c("Preheat oven to 350°F Grease an 8x8 cak... [83668 rows x 16 columns] ``` -------------------------------- ### Execute Recommendation Inference Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Use the pipeline to transform input data and retrieve indices of recommended food items. ```python pipeline.transform(extracted_data.iloc[0:1,6:15].to_numpy())[0] ``` ```python extracted_data.iloc[pipeline.transform(extracted_data.iloc[0:1,6:15].to_numpy())[0]] ``` -------------------------------- ### Create Recommendation Pipeline Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Wrap the scaler and neighbor search into a single Scikit-Learn pipeline for streamlined inference. ```python from sklearn.pipeline import Pipeline from sklearn.preprocessing import FunctionTransformer transformer = FunctionTransformer(neigh.kneighbors,kw_args={'return_distance':False}) pipeline=Pipeline([('std_scaler',scaler),('NN',transformer)]) ``` -------------------------------- ### Load Dataset Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Reads the recipes CSV file from the specified Kaggle input path. ```python data=pd.read_csv('/kaggle/input/foodcom-recipes-and-reviews/recipes.csv') ``` -------------------------------- ### POST /generate-meal-plan/ Source: https://github.com/zakaria-narjis/nutrimind/blob/main/README.md Generates a full daily meal plan based on the user's personal health data. ```APIDOC ## POST /generate-meal-plan/ ### Description Generates a full daily meal plan from personal health data. ### Method POST ### Endpoint /generate-meal-plan/ ### Request Body - **age** (integer) - Required - User age - **height** (integer) - Required - User height in cm - **weight** (integer) - Required - User weight in kg - **gender** (string) - Required - User gender - **activity** (string) - Required - Activity level description - **number_of_meals** (integer) - Required - Number of meals per day - **weight_loss** (string) - Required - Weight goal preference ### Response - **BMI** (float) - Body Mass Index - **BMR** (float) - Basal Metabolic Rate - **daily_calorie_targets** (integer) - Recommended daily calories - **recommended_recipes** (array) - List of recipes per meal ``` -------------------------------- ### Cite the NutriMind project Source: https://github.com/zakaria-narjis/nutrimind/blob/main/README.md Use this BibTeX entry to cite the Diet recommendation system software in academic or technical publications. ```bibtex @software{narjis_2024_12507829, author = {Narjis, Zakaria}, title = {Diet recommendation system}, month = jun, year = 2024, publisher = {Zenodo}, version = {v1.0.1}, doi = {10.5281/zenodo.12507829}, url = {https://doi.org/10.5281/zenodo.12507829} } ``` -------------------------------- ### Import Data Science Libraries Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Initial imports for data manipulation, numerical operations, machine learning, and visualization. ```python import pandas as pd import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ``` -------------------------------- ### Define Recommendation Pipeline Functions Source: https://github.com/zakaria-narjis/nutrimind/blob/main/food-recommendation-system.ipynb Functions to scale data, initialize a nearest neighbors model, build a scikit-learn pipeline, filter data, and execute recommendations. ```python def scaling(dataframe): scaler=StandardScaler() prep_data=scaler.fit_transform(dataframe.iloc[:,6:15].to_numpy()) return prep_data,scaler def nn_predictor(prep_data): neigh = NearestNeighbors(metric='cosine',algorithm='brute') neigh.fit(prep_data) return neigh def build_pipeline(neigh,scaler,params): transformer = FunctionTransformer(neigh.kneighbors,kw_args=params) pipeline=Pipeline([('std_scaler',scaler),('NN',transformer)]) return pipeline def extract_data(dataframe,ingredient_filter,max_nutritional_values): extracted_data=dataframe.copy() for column,maximum in zip(extracted_data.columns[6:15],max_nutritional_values): extracted_data=extracted_data[extracted_data[column]