You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
590 B
17 lines
590 B
import matplotlib.pyplot as plt
|
|
from sklearn.cluster import DBSCAN
|
|
|
|
def perform_dbscan_clustering(data, data_name, eps, min_samples):
|
|
x = data[data_name].to_numpy()
|
|
dbscan = DBSCAN(eps=eps, min_samples=min_samples)
|
|
y_dbscan = dbscan.fit_predict(x)
|
|
|
|
fig = plt.figure()
|
|
if len(data_name) == 2:
|
|
ax = fig.add_subplot(projection='rectilinear')
|
|
plt.scatter(x[:, 0], x[:, 1], c=y_dbscan, s=50, cmap="viridis")
|
|
else:
|
|
ax = fig.add_subplot(projection='3d')
|
|
ax.scatter(x[:, 0], x[:, 1], x[:, 2], c=y_dbscan, s=50, cmap="viridis")
|
|
return fig
|