Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. import scipy as sci
  4. from sklearn import preprocessing
  5. from sklearn.cluster import DBSCAN
  6.  
  7. df = pd.read_csv('mystery.csv', header=None)
  8. scaler = preprocessing.MinMaxScaler(feature_range=(-1, 1))
  9. scaler.fit(df)
  10. df = pd.DataFrame(scaler.transform(df))
  11.  
  12.  
  13. def ezScatter(x, y):
  14. plt.scatter(df[x], df[y])
  15. plt.xlabel(x)
  16. plt.ylabel(y)
  17. plt.title((str(x) + "->" + str(y)))
  18. plt.show()
  19.  
  20.  
  21. def ezDB(x, y):
  22. toFit = df[[x, y]].copy()
  23. dbscan = DBSCAN(eps=.10, min_samples=4)
  24. model = dbscan.fit(toFit)
  25. clusterLabels = model.labels_
  26.  
  27. plt.scatter(df[x], df[y], c=clusterLabels, cmap='hsv')
  28. plt.xlabel(x)
  29. plt.ylabel(y)
  30. plt.title((str(x) + "->" + str(y) + " DBSCAN"))
  31. plt.show()
  32.  
  33.  
  34. pd.plotting.scatter_matrix(df, cmap='prism')
  35. plt.show()
  36.  
  37. print("ctrl c to quit. Too lazy for an escape ")
  38. while True:
  39. xFig = int(input("X to examine: "))
  40. yFig = int(input("Y to examine: "))
  41. ezScatter(xFig, yFig)
  42. ezDB(xFig, yFig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement