Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import pandas as pd
  2. import pickle
  3. from sklearn.cluster import KMeans
  4.  
  5. frames = [pd.read_hdf(fin) for fin in ifiles]
  6. data = pd.concat(frames, ignore_index=True, axis=0)
  7. data.dropna(inplace=True)
  8.  
  9. k = 12
  10. x = pd.concat(data['A'], data['B'], data['C'], axis=1, keys=['A','B','C'])
  11. model = KMeans(n_clusters=k, random_state=0, n_jobs = -2)
  12. model.fit(x)
  13.  
  14. pickle.dump(model, open(filename, 'wb'))
  15.  
  16. array([[-2.26732099, 0.24895614, 2.34840191],
  17. [-2.26732099, 0.22270912, 1.88942378],
  18. [-1.99246557, 0.04154312, 2.63458941],
  19. ...,
  20. [-4.29596287, 1.97036309, -0.22767511],
  21. [-4.26055474, 1.72347591, -0.18185197],
  22. [-4.15980382, 1.73176239, -0.30781225]])
  23.  
  24. KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,
  25. n_clusters=12, n_init=10, n_jobs=-2, precompute_distances='auto',
  26. random_state=0, tol=0.0001, verbose=0)
  27.  
  28. modelnew = pickle.load(open('test.pkl', 'rb'))
  29. modelnew.predict(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement