Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
- import sklearn
- # Create Data
- X = [2, 2, 8, 5, 7, 6, 1, 4]
- Y = [10, 5, 4, 8, 5, 4, 2, 9]
- labels = ["x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8"]
- ddata = pd.DataFrame({"X": X, "Y": Y}, index=labels)
- # Plot data
- plt.scatter(ddata.X, ddata.Y)
- for i in range(len(ddata.index)):
- plt.text(ddata.loc[labels[i], "X"], ddata.loc[labels[i], "Y"], '%s' % (str(labels[i])), size=15, zorder=1)
- plt.title("Data 2-D")
- plt.xlabel("X")
- plt.ylabel("Y")
- plt.show()
- # DBSCAN
- from sklearn.cluster import DBSCAN
- clustering = DBSCAN(eps=2, min_samples=2).fit(ddata)
- plt.scatter(ddata.X, ddata.Y, c=clustering.labels_, cmap="spring")
- for i in range(len(ddata.index)):
- plt.text(ddata.loc[labels[i], "X"], ddata.loc[labels[i], "Y"], '%s' % (str(labels[i])), size=15, zorder=1)
- plt.xlabel("X")
- plt.ylabel("Y")
- plt.title("DBSCAN(eps=2, minPts=2)")
- plt.show()
- clustering = DBSCAN(eps=3.5, min_samples=2).fit(ddata)
- plt.scatter(ddata.X, ddata.Y, c=clustering.labels_, cmap="spring")
- for i in range(len(ddata.index)):
- plt.text(ddata.loc[labels[i], "X"], ddata.loc[labels[i], "Y"], '%s' % (str(labels[i])), size=15, zorder=1)
- plt.xlabel("X")
- plt.ylabel("Y")
- plt.title("DBSCAN(eps=3.5, minPts=2)")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement