0
0
SciPydata~30 mins

Hierarchical clustering (linkage) in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Hierarchical clustering (linkage)
📖 Scenario: You work in a small shop that sells fruits. You want to group similar fruits based on their sweetness and crunchiness scores to understand which fruits are alike.
🎯 Goal: Build a simple hierarchical clustering using linkage to group fruits by their sweetness and crunchiness.
📋 What You'll Learn
Create a dictionary with fruit names as keys and their sweetness and crunchiness scores as values.
Create a list of fruit names to keep track of the order.
Use scipy's linkage function to perform hierarchical clustering on the fruit scores.
Print the linkage matrix to see the clustering result.
💡 Why This Matters
🌍 Real World
Hierarchical clustering helps group similar items, like fruits, customers, or documents, based on their features.
💼 Career
Data scientists use hierarchical clustering to find natural groups in data, which helps in marketing, biology, and many other fields.
Progress0 / 4 steps
1
Create the fruit data dictionary
Create a dictionary called fruit_data with these exact entries: 'Apple': [7, 6], 'Banana': [10, 2], 'Cherry': [6, 7], 'Date': [9, 3], 'Elderberry': [5, 8].
SciPy
Need a hint?

Use curly braces to create a dictionary. Each fruit name is a key, and the value is a list with two numbers.

2
Create a list of fruit names
Create a list called fruit_names containing the fruit names in this exact order: 'Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'.
SciPy
Need a hint?

Use square brackets to create a list with the fruit names in the given order.

3
Perform hierarchical clustering using linkage
Import linkage from scipy.cluster.hierarchy. Create a list called data_points that contains the fruit scores in the order of fruit_names. Then use linkage(data_points, method='single') to perform hierarchical clustering and save the result in a variable called linkage_matrix.
SciPy
Need a hint?

Use a list comprehension to get the scores in the order of fruit_names. Then call linkage with method='single'.

4
Print the linkage matrix
Print the variable linkage_matrix to display the hierarchical clustering result.
SciPy
Need a hint?

Use print(linkage_matrix) to show the clustering result.