Advertisement
Guest User

test

a guest
Nov 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. # code: imports and data ->
  2. import ​​scipy.cluster.hierarchyas ​​hier from ​​matplotlib ​import ​​pyplot ​as ​​plt from ​​scipy.spatial.distanceimport ​​pdist import ​​numpy ​as ​​np
  3. import ​​distance # <- you most likely need pip install distance here data = ?
  4. labels = ?
  5. # The levenshtein distance matrix ->
  6. mat = np.zeros((len(data),len(data)), ​dtype​=int) for ​​i ​in ​​range(0,len(data)):
  7. for ​​j ​in ​​range(0,len(data)):
  8. mat[i][j] = distance.levenshtein(data[i], data[j])print(mat[i][j], ​end​=""​​)
  9. print("​​\n​​"​​)
  10. mat = pdist(mat)# make an upper triangle matrix
  11. # The hierarchy clustering ->
  12. # here run scipy.cluster.hierarchy.linkage() on triangle matrix
  13. z =?
  14. fig = plt.figure(​figsize​=(25,10))
  15. # here run scipy.cluster.hierarchy.dendrogram() with the linkage z and labels = labels dn =?
  16. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement