0

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.

Vivek Kumar
  • 35,217
  • 8
  • 109
  • 132
Luo Zin-Han
  • 11
  • 1
  • 2

1 Answers1

0

DBSCAN clusters do not use the concept of a center or a radius.

Clusters can be any shape, and if you consider the examples in the Wikipedia article, the cluster"center" could be paid off the cluster if you have such banana shaped clusters.

Either way, there is no API to get a "center". Whatever you use, you'll Haversine to find it yourself. Instead of the arithmetic mean, consider something graph based, like graph centrality.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194