Skip to content

Instantly share code, notes, and snippets.

@Jviejo
Last active April 9, 2019 16:37
Show Gist options
  • Save Jviejo/6d61356015dd50af35bdc35a79d04150 to your computer and use it in GitHub Desktop.
Save Jviejo/6d61356015dd50af35bdc35a79d04150 to your computer and use it in GitHub Desktop.
dendograma.py
# Load the Pandas libraries with alias 'pd'
import pandas as pd
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
from sklearn import datasets
import numpy as np
# Read data from file 'filename.csv'
# (in the same directory that your python process is based)
# Control delimiters, rows, column names with read_csv (see later)
data = pd.read_csv("C:\\Users\\jviejo\\womantech\\python\\small.csv", sep='\t')
print(data.head())
X=data
#single, media, complete, ward
Z = linkage(X, 'complete' , metric='euclidean')
plt.figure(figsize=(10, 8))
plt.title('Dendograma single')
plt.xlabel('Indice')
plt.ylabel('Distancia')
max_d = 10
dendrogram(
Z,
leaf_rotation=90.,
leaf_font_size=8.,
show_contracted=True
)
plt.axhline(y= max_d, c ='k')
plt.show()
PRICE,MAINT,DOORS,PERSONS,SAFETY,CLASS
40000,2000,2,2,1,0
30000,500,3,5,3,1
10000,2000,5,4,3,1
20000,1000,2,4,2,1
40000,2000,5,2,3,0
30000,1000,4,2,3,0
30000,2000,3,4,3,0
20000,1500,2,2,2,0
10000,500,3,5,2,1
40000,1000,2,4,3,1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment