SHARE
TWEET

Untitled

a guest Apr 19th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pandas import DataFrame
  2. import matplotlib.pyplot as plt
  3. from sklearn.cluster import KMeans
  4. import tkinter as tk
  5. from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  6.  
  7. Data = {'x': [25,34,22,27,33,33,31,22,35,34,67,54,57,43,50,57,59,52,65,47,49,48,35,33,44,45,38,43,51,46],
  8.         'y': [79,51,53,78,59,74,73,57,69,75,51,32,40,47,53,36,35,58,59,50,25,20,14,12,20,5,29,27,8,7]
  9.        }
  10.  
  11. df = DataFrame(Data,columns=['x','y'])
  12.  
  13. kmeans = KMeans(n_clusters=3).fit(df)
  14. centroids = kmeans.cluster_centers_
  15.  
  16. root= tk.Tk()
  17.  
  18. canvas1 = tk.Canvas(root, width = 100, height = 100)
  19. canvas1.pack()
  20.  
  21. label1 = tk.Label(root, text=centroids, justify = 'center')
  22. canvas1.create_window(70, 50, window=label1)
  23.  
  24. figure1 = plt.Figure(figsize=(5,4), dpi=100)
  25. ax1 = figure1.add_subplot(111)
  26. ax1.scatter(df['x'], df['y'], c= kmeans.labels_.astype(float), s=50, alpha=0.5)
  27. ax1.scatter(centroids[:, 0], centroids[:, 1], c='red', s=50)
  28. scatter1 = FigureCanvasTkAgg(figure1, root)
  29. scatter1.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH)
  30.  
  31. root.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top