Published
Edited
Jun 15, 2022
5 forks
Importers
25 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
SummaryTable(seeds_df)
Insert cell
Insert cell
seeds_lookup = ({
1: "Kama",
2: "Rosa",
3: "Canadian"
})
Insert cell
seeds_label = seeds_df.map((row) => seeds_lookup[row["type of seed"]])
Insert cell
seeds_no_label_df = seeds_df.map(
({ "type of seed": undefined, ...headers }) => ({
...headers
})
)
Insert cell
Insert cell
seeds_df_sc = scale(seeds_no_label_df)
Insert cell
SummaryTable(seeds_df_sc)
Insert cell
Insert cell
dist_mat = dist(asMatrix(seeds_df_sc), distance.euclidean)
Insert cell
Insert cell
hclust_avg = new hclust(dist_mat, {
method: "average",
isDistanceMatrix: true
})
Insert cell
Insert cell
dendrogram(hclust_avg)
Insert cell
Insert cell
cut_avg = hclust_avg.group(3)
Insert cell
Insert cell
plot_dendrogram_3 = dendrogram(cut_avg, {
h: 3,
width: 500,
//height: 400,
hideLabels: true
})
Insert cell
Insert cell
clustered_groups = Object.entries(
cut_avg.children.reduce((lookup, group, groupIndex) => {
group.traverse((child) => {
if (child.index > -1) lookup[child.index] = groupIndex + 1;
});
return lookup;
}, {})
).map((arr) => arr[1])
Insert cell
Insert cell
seeds_df_clustered = seeds_df.map((row, index) => ({
...row,
cluster_result: clustered_groups[index]
}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dendrogram(hclust_avg_simple, { h: 2.5 })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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