I want to find each cluster's center and radius. What can I do? Please help me. Here is my code it contain dbscan and meanshifts two result. The points is random and now i want to find each cluster's center and radius.
import numpy as np
import matplotlib.pyplot as plt
from sklearn import cluster
def cluster_plots(set, colours1='gray', colours2='gray',
title1='Plot 1', title2='Plot 2'):
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.set_size_inches(6, 3)
ax1.set_title(title1, fontsize=14)
ax1.set_xlim(min(set[:, 0]), max(set[:, 0]))
ax1.set_ylim(min(set[:, 1]), max(set[:, 1]))
ax1.scatter(set[:, 0], set[:, 1], s=8, lw=0, c=colours1)
ax2.set_title(title2, fontsize=14)
ax2.set_xlim(min(set[:, 0]), max(set[:, 0]))
ax2.set_ylim(min(set[:, 1]), max(set[:, 1]))
ax2.scatter(set[:, 0], set[:, 1], s=8, lw=0, c=colours2)
fig.tight_layout()
plt.show()
def data_generator():
clust1 = np.random.normal(5, 2, (1000, 2))
clust2 = np.random.normal(15, 3, (1000, 2))
clust3 = np.random.multivariate_normal([17, 3], [[1, 0], [0, 1]], 1000)
clust4 = np.random.multivariate_normal([2, 16], [[1, 0], [0, 1]], 1000)
return np.concatenate((clust1, clust2, clust3, clust4))
datapoints = data_generator()
bandwidths = [cluster.estimate_bandwidth(dataset, quantile=0.1) for dataset in [datapoints]]
meanshifts = [cluster.MeanShift(bandwidth=band, bin_seeding=True).fit(dataset) for dataset, band in zip([datapoints], bandwidths)]
dbscan = cluster.DBSCAN(eps=1, min_samples=10, metric='euclidean').fit_predict(datapoints)
cluster_plots(datapoints, dbscan,meanshifts[0].predict(datapoints),title1='DBScan', title2='Meanshifts')
I don't know what should I add can get what i want.