Hierarchical clustering: single method
आइए वही footfall डेटासेट इस्तेमाल करें और देखें कि अगर हम क्लस्टरिंग के लिए अलग method लें तो क्या बदलाव दिखते हैं.
डेटा एक pandas DataFrame comic_con में है. x_scaled और y_scaled वे कॉलम नाम हैं जिनमें किसी समय-बिंदु पर लोगों के standardized X और Y coordinates हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में क्लस्टर विश्लेषण
अभ्यास निर्देश
scipy.cluster.hierarchyसेfclusterऔरlinkageइम्पोर्ट करें.linkage()फंक्शन मेंsinglemethod का उपयोग करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the fcluster and linkage functions
from ____ import ____, ____
# Use the linkage() function
distance_matrix = ____(comic_con[[____, ____]], ____ = ____, metric = ____)
# Assign cluster labels
comic_con['cluster_labels'] = ____(____, ____, ____)
# Plot clusters
sns.scatterplot(x='x_scaled', y='y_scaled',
hue='cluster_labels', data = comic_con)
plt.show()