Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Extracting the cluster labels from a dendrogram

# Perform the necessary imports
import pandas as pd
from scipy.cluster.hierarchy import fcluster

# Use fcluster to extract labels: labels
labels = fcluster(mergings, ''specify an height'', criterion='distance')

# Create a DataFrame with labels and varieties as columns: df
df = pd.DataFrame({'labels': labels, 'varieties': varieties})

# Create crosstab: ct
ct = pd.crosstab(df['labels'], df['varieties'])

# Display ct
print(ct)
Source by campus.datacamp.com #
 
PREVIOUS NEXT
Tagged: #Extracting #cluster #labels #dendrogram
ADD COMMENT
Topic
Name
1+5 =