-
-
Save PulkitS01/8ac9bf3b54eb59b4e1d4eaa21d3d774e to your computer and use it in GitHub Desktop.
Hierarchical clustering
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
plt.figure(figsize=(10, 7)) | |
plt.scatter(data_scaled['Milk'], data_scaled['Grocery'], c=cluster.labels_) |
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
import scipy.cluster.hierarchy as shc | |
plt.figure(figsize=(10, 7)) | |
plt.title("Dendrograms") | |
dend = shc.dendrogram(shc.linkage(data_scaled, method='ward')) |
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
plt.figure(figsize=(10, 7)) | |
plt.title("Dendrograms") | |
dend = shc.dendrogram(shc.linkage(data_scaled, method='ward')) | |
plt.axhline(y=6, color='r', linestyle='--') |
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
from sklearn.cluster import AgglomerativeClustering | |
cluster = AgglomerativeClustering(n_clusters=2, affinity='euclidean', linkage='ward') | |
cluster.fit_predict(data_scaled) |
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
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline |
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
data = pd.read_csv('Wholesale customers data.csv') | |
data.head() |
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
from sklearn.preprocessing import normalize | |
data_scaled = normalize(data) | |
data_scaled = pd.DataFrame(data_scaled, columns=data.columns) | |
data_scaled.head() |
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
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
Could someone please say where is the wholesale customers data csv file?