Public
Edited
Jun 6, 2023
Insert cell
Insert cell
csv = FileAttachment("heart_dataset@2.csv")
.csv()
Insert cell
data = csv.map((d, i) => ({ ...d, id: i }))
Insert cell
Insert cell
Insert cell
group_data = data.reduce((groups, obj) => {
const algo = obj.algo;
const line_step = parseInt(obj.line_step);

if (!groups[algo]) { // group by algo first
groups[algo] = {};
}

//then group the first point of every line, 2nd group of every line, ...
if (!groups[algo][line_step]) { // use line_step as array accessor
groups[algo][line_step] = [];
}

groups[algo][line_step].push(obj.id);

return groups;
}, {});
Insert cell
label_grouped_data = Object.values(group_data).map((g, i) => {
const algoLabel = "" + i + "-";
const prefixed = Object.entries(g).reduce((result, [key, value]) => {
const prefixedKey = algoLabel + key;
result[prefixedKey] = value;
return result;
}, {});
return prefixed;
})
Insert cell
flat_group_data = label_grouped_data
.flatMap(obj => Object.entries(obj))
.map((g,i) => [i, g[1], g[0]])
Insert cell
pse = ({
samples: [{ // the data
columns: ['line', 'x', 'y', 'algo'], // attributes of the items
index: data.map((d) => d.id), //ids of the items
data: data.map((d) => ([ // remaining data of the items
parseInt(d.line),
parseFloat(d.x),
parseFloat(d.y),
parseInt(d.algo)
]))
}],
preselection: [ // ??
{
columns: [
"preselect"
],
index: [],
data: []
}
],
clusters: [{ // predefined groups
columns: ['id', 'items', 'name'], // attributes of the groups
index: flat_group_data.map(g => g[0]), // index for each created group
data: flat_group_data
}],
edges: [{
columns: [
"id",
"source",
"destination",
"name"
],
index: [],
data: []
}
]
})
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