0
0
SciPydata~30 mins

Why clustering groups similar data in SciPy - See It in Action

Choose your learning style9 modes available
Why clustering groups similar data
📖 Scenario: Imagine you have a small shop and you want to group your customers based on their shopping habits. Grouping similar customers helps you understand their preferences better and offer them personalized deals.
🎯 Goal: You will create a simple dataset of customer shopping amounts, set a threshold for grouping, apply clustering using scipy, and then display the groups formed.
📋 What You'll Learn
Create a list of customer shopping amounts
Set a distance threshold for clustering
Use scipy.cluster.hierarchy to cluster the data
Print the cluster labels for each customer
💡 Why This Matters
🌍 Real World
Clustering helps businesses group customers with similar behaviors to target marketing and improve service.
💼 Career
Data scientists use clustering to find patterns in data, segment customers, and make data-driven decisions.
Progress0 / 4 steps
1
Create the customer data list
Create a list called shopping_amounts with these exact values: 5, 7, 15, 18, 25, 30.
SciPy
Need a hint?

Use square brackets to create a list and separate numbers with commas.

2
Set the clustering distance threshold
Create a variable called distance_threshold and set it to 10.
SciPy
Need a hint?

Just assign the number 10 to the variable distance_threshold.

3
Cluster the shopping amounts
Import linkage and fcluster from scipy.cluster.hierarchy. Use linkage on shopping_amounts with method 'complete' and store in linked. Then create clusters using fcluster with linked, distance_threshold, and criterion 'distance'.
SciPy
Need a hint?

Convert each number to a list like [x] before clustering because linkage expects 2D data.

4
Print the cluster labels
Print the clusters list to show which group each shopping amount belongs to.
SciPy
Need a hint?

Use print(clusters.tolist()) to display the cluster labels as a list.