K-means clustering - foodstuff
Nutrients in the food we consume can be classified by the role they play in building body mass. These nutrients can be divided into either macronutrients or essential micronutrients. Some examples of macronutrients are carbohydrates, protein, and fat while some examples of essential micronutrients are vitamins, minerals, and water.
Getting ready
Let's get started with the recipe.
Step 1 - collecting and describing data
In order to perform K-means clustering we shall be using a dataset collected on various food items and their respective Energy
, Protein
, Fat
, Calcium
, and Iron
content. The numeric variables are:
Energy
Protein
Fat
Calcium
Iron
The non-numeric variable is:
Food
How to do it...
Let's get into the details.
Step 2 - exploring data
Note
Version info: Code for this page was tested in R version 3.2.3 (2015-12-10).
Loading the cluster()
library.
> library(cluster)
Let's explore the data and understand relationships among the variables. We'll begin by importing the...