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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more