Published
Edited
Apr 20, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
obesity_data = d3.csvParse(await FileAttachment("ObesityDataSet_raw_and_data_sinthetic.csv").text(), function(d) {
return {
gender: d.Gender,
age: +d.Age,
height: +d.Height,
weight: +d.Weight,
main_meals: +d.NCP,
family_history_with_overweight: d.family_history_with_overweight,
high_caloric_food: d.FAVC,
vegetables: +d.FCVC,
physical_activity: +d.FAF,
tue: +d.TUE,
alcohol: d.CALC,
mtrans: d.MTRANS,
obesity_type: d.NObeyesdad
};
}).sort(function (a, b) {return a.NObeyesdad - b.NObeyesdad;});
Insert cell
transformed_obesity_data = obesity_data.filter(function(entry){return entry.age <= 45 && entry.age >= 16}).map(item => {
var temp = Object.assign({}, item);
temp["vegetables"] = Math.floor(temp["vegetables"]);
temp["physical_activity"] = Math.floor(temp["physical_activity"]);
temp["main_meals"] = Math.floor(temp["main_meals"]);
temp["height"] = temp["height"] * 39.3701;
temp["weight"] = temp["weight"] * 2.20462;
temp["age"] = Math.floor(temp["age"])
if(temp["obesity_type"] == "Insufficient_Weight"){
temp["obesity_type"] = "1. Insufficient_Weight"
}
else if(temp["obesity_type"] == "Normal_Weight"){
temp["obesity_type"] = "2. Normal_Weight"
}
else if(temp["obesity_type"] == "Overweight_Level_I"){
temp["obesity_type"] = "3. Overweight_Level_I"
}
else if(temp["obesity_type"] == "Overweight_Level_II"){
temp["obesity_type"] = "4. Overweight_Level_II"
}
else if(temp["obesity_type"] == "Obesity_Type_I"){
temp["obesity_type"] = "5. Obesity_Type_I"
}
else if(temp["obesity_type"] == "Obesity_Type_II"){
temp["obesity_type"] = "6. Obesity_Type_II"
}
else if(temp["obesity_type"] == "Obesity_Type_III"){
temp["obesity_type"] = "7. Obesity_Type_III"
}
return temp;
});
Insert cell
obesity_types = ["1. Insufficient_Weight","2. Normal_Weight","3. Overweight_Level_I","4. Overweight_Level_II","5. Obesity_Type_I","6. Obesity_Type_II", "7. Obesity_Type_III"]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
import {kmeans} from "@spond/k-means-clustering-algorithm"
Insert cell
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
import {printTable} from '@uwdata/data-utilities'
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more