import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import zscore
from scipy.cluster.hierarchy import linkage, dendrogram, cut_tree


# perform cluster analysis
file='https://raw.githubusercontent.com/grbruns/cst383/master/protein.csv'
df = pd.read_csv(file, index_col='Country')
X = df.apply(zscore).values
Z = linkage(X, method='complete')

# plot dendrogram
plt.figure(figsize=(10,5))
dendrogram(Z, labels=df.index, leaf_rotation=75, leaf_font_size=14)
plt.ylabel("Height")

# get specific num of clusters
Z = linkage(X, method='complete')
num_clusts = 3
labels = cut_tree(Z, num_clusts)[:,0]

# plot dendrogram
plt.figure(figsize=(10,5))
dendrogram(Z, labels=df.index, leaf_rotation=75, leaf_font_size=14, color_threshold=6)
plt.ylabel("Height")

