Skip to content

Instantly share code, notes, and snippets.

@PulkitS01
Created May 17, 2019 10:58
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save PulkitS01/8ac9bf3b54eb59b4e1d4eaa21d3d774e to your computer and use it in GitHub Desktop.
Hierarchical clustering
plt.figure(figsize=(10, 7))
plt.scatter(data_scaled['Milk'], data_scaled['Grocery'], c=cluster.labels_)
import scipy.cluster.hierarchy as shc
plt.figure(figsize=(10, 7))
plt.title("Dendrograms")
dend = shc.dendrogram(shc.linkage(data_scaled, method='ward'))
plt.figure(figsize=(10, 7))
plt.title("Dendrograms")
dend = shc.dendrogram(shc.linkage(data_scaled, method='ward'))
plt.axhline(y=6, color='r', linestyle='--')
from sklearn.cluster import AgglomerativeClustering
cluster = AgglomerativeClustering(n_clusters=2, affinity='euclidean', linkage='ward')
cluster.fit_predict(data_scaled)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
data = pd.read_csv('Wholesale customers data.csv')
data.head()
from sklearn.preprocessing import normalize
data_scaled = normalize(data)
data_scaled = pd.DataFrame(data_scaled, columns=data.columns)
data_scaled.head()
@prasadhebbar
Copy link

Could someone please say where is the wholesale customers data csv file?

@robinsdeepak
Copy link

Could someone please say where is the wholesale customers data csv file?

https://archive.ics.uci.edu/ml/machine-learning-databases/00292/Wholesale%20customers%20data.csv

@JandyZ22
Copy link

Hello. I would like to ask a question, will the clustering results be different if the input order is different?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment