0
0
SciPydata~30 mins

Dendrogram visualization in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Dendrogram visualization
📖 Scenario: You work in a small company that wants to group similar products based on their features. You have collected data about the products and want to see how they cluster together visually.
🎯 Goal: Build a dendrogram visualization using scipy to show how products group based on their features.
📋 What You'll Learn
Create a data dictionary with product names and their feature values
Set a linkage method variable for clustering
Use scipy.cluster.hierarchy.linkage to compute clusters
Use scipy.cluster.hierarchy.dendrogram to plot the dendrogram
Print the dendrogram plot
💡 Why This Matters
🌍 Real World
Dendrograms help businesses group similar items or customers to understand patterns and make decisions.
💼 Career
Data scientists and analysts use dendrograms to visualize hierarchical clusters in marketing, biology, and many other fields.
Progress0 / 4 steps
1
Create product features data
Create a dictionary called products with these exact entries: 'ProductA': [1.0, 2.0], 'ProductB': [1.5, 1.8], 'ProductC': [5.0, 8.0], 'ProductD': [6.0, 9.0]
SciPy
Need a hint?

Use curly braces to create a dictionary. Each product name is a key, and its features are a list of two numbers.

2
Set linkage method
Create a variable called linkage_method and set it to the string 'ward' to specify the clustering method.
SciPy
Need a hint?

Assign the string 'ward' to the variable linkage_method.

3
Compute linkage matrix
Import linkage from scipy.cluster.hierarchy. Create a list called data_points containing the feature lists from products. Use linkage(data_points, method=linkage_method) and save the result in a variable called Z.
SciPy
Need a hint?

Use a list comprehension to get the feature lists from the dictionary values.

4
Plot dendrogram
Import dendrogram from scipy.cluster.hierarchy and matplotlib.pyplot as plt. Use dendrogram(Z, labels=list(products.keys())) to create the dendrogram plot. Then call plt.show() to display it.
SciPy
Need a hint?

Use dendrogram with Z and labels=list(products.keys()). Then call plt.show() to display the plot.