What is good food?
π Background
You and your friend have gotten into a debate about nutrition. Your friend follows a high-protein diet and does not eat any carbohydrates (no grains, no fruits). You claim that a balanced diet should contain all nutrients but should be low in calories. Both of you quickly realize that most of what you know about nutrition comes from mainstream and social media.
Being the data scientist that you are, you offer to look at the data yourself to answer a few key questions.
πΎ The data
You source nutrition data from USDA's FoodData Central website. This data contains the calorie content of 7,793 common foods, as well as their nutritional composition. Each row represents one food item, and nutritional values are based on a 100g serving. Here is a description of the columns:
- FDC_ID: A unique identifier for each food item in the database.
- Item: The name or description of the food product.
- Category: The category or classification of the food item, such as "Baked Products" or "Vegetables and Vegetable Products".
- Calories: The energy content of the food, presented in kilocalories (kcal).
- Protein: The protein content of the food, measured in grams.
- Carbohydrate: The carbohydrate content of the food, measured in grams.
- Total fat: The total fat content of the food, measured in grams.
- Cholesterol: The cholesterol content of the food, measured in milligrams.
- Fiber: The dietary fiber content of the food, measured in grams.
- Water: The water content of the food, measured in grams.
- Alcohol: The alcohol content of the food (if any), measured in grams.
- Vitamin C: The Vitamin C content of the food, measured in milligrams.
πͺ Competition challenge
Create a report that covers the following:
- Which fruit has the highest vitamin C content? What are some other sources of vitamin C?
- Describe the relationship between the calories and water content of a food item.
- What are the possible drawbacks of a zero-carb diet? What could be the drawbacks of a very high-protein diet?
- According to the Cleveland Clinic website, a gram of fat has around 9 kilocalories, and a gram of protein and a gram of carbohydrate contain 4 kilocalories each. Fit a linear model to test whether these estimates agree with the data.
- Analyze the errors of your linear model to see what could be the hidden sources of calories in food.
π§ββοΈ Judging criteria
This competition is for helping to understand how competitions work. This competition will not be judged.
β
 Checklist before publishing into the competition
- Rename your workspace to make it descriptive of your work. N.B. you should leave the notebook name as notebook.ipynb.
- Remove redundant cells like the judging criteria, so the workbook is focused on your story.
- Make sure the workbook reads well and explains how you found your insights.
- Try to include an executive summary of your recommendations at the beginning.
- Check that all the cells run without error
βοΈ Time is ticking. Good luck!
source('https://raw.githubusercontent.com/ribeiropvb/Util/main/install_packages_if_not_exist.R')
packages <- c( 'pacman','tidyverse','janitor', 'magrittr', 'fields', 'VIM', 'ggfortify', 'hnp', 'caret', 'glmnet' )
install_packages_if_not_exist(packages)
pacman::p_load( tidyverse, janitor, magrittr, fields, VIM, ggfortify, hnp, caret, glmnet )
theme_default <- theme_light()+
  theme(
    panel.grid.major = element_blank()
    , panel.grid.minor = element_blank()
  )df_food <- readr::read_csv('nutrition.csv', show_col_types = FALSE)  %>% janitor::clean_names()
df_fooddf_food %<>% mutate(
	calories = str_remove(calories, ' kcal') %>% as.numeric()
	, protein = str_remove(protein, ' g') %>% as.numeric()
	, carbohydrate = str_remove(carbohydrate, ' g') %>% as.numeric()
	, total_fat = str_remove(total_fat, ' g') %>% as.numeric()
	, cholesterol = str_remove(cholesterol, ' mg') %>% as.numeric()
	, fiber = str_remove(fiber, ' g') %>% as.numeric()
	, water = str_remove(water, ' g') %>% as.numeric()
	, alcohol = str_remove(alcohol, ' g') %>% as.numeric()
	, vitamin_c = str_remove(vitamin_c, ' mg') %>% as.numeric()
)df_food %>%
	select_if( is.numeric ) %>% 
	fields::stats() %>% t() %>% 
	round(2)na_analysis <- aggr(df_food)
summary(na_analysis)df_food <- VIM::kNN(df_food %>% dplyr::select(-ends_with('imp')))
df_food <- df_food %>% dplyr::select(-ends_with('imp'))
na_analysis <- aggr(df_food %>% dplyr::select(-ends_with('imp')))
summary(na_analysis)df_food %>%
	select_if( is.numeric ) %>% 
	fields::stats() %>% t() %>% 
	round(2)Which fruit has more Vitamin C
Question to be answer:
- Which fruit has the highest vitamin C content? What are some other sources of vitamin C?
β
β