Last active
May 11, 2018 19:16
-
-
Save vihar/c2163bae9f39a657f5fd51d18ab6a8d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing Modules | |
from scipy.cluster.hierarchy import linkage, dendrogram | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
# Reading the DataFrame | |
seeds_df = pd.read_csv( | |
"https://raw.githubusercontent.com/vihar/unsupervised-learning-with-python/master/seeds-less-rows.csv") | |
# Remove the grain species from the DataFrame, save for later | |
varieties = list(seeds_df.pop('grain_variety')) | |
# Extract the measurements as a NumPy array | |
samples = seeds_df.values | |
""" | |
Perform hierarchical clustering on samples using the | |
linkage() function with the method='complete' keyword argument. | |
Assign the result to mergings. | |
""" | |
mergings = linkage(samples, method='complete') | |
""" | |
Plot a dendrogram using the dendrogram() function on mergings, | |
specifying the keyword arguments labels=varieties, leaf_rotation=90, | |
and leaf_font_size=6. | |
""" | |
dendrogram(mergings, | |
labels=varieties, | |
leaf_rotation=90, | |
leaf_font_size=6, | |
) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment