|
@@ -1,5 +1,6 @@
|
|
|
from sklearn.cluster import DBSCAN
|
|
|
from sklearn import metrics
|
|
|
+from collections import namedtuple
|
|
|
import numpy as np
|
|
|
import matplotlib.pyplot as plt
|
|
|
from itertools import groupby
|
|
@@ -57,4 +58,17 @@ if __name__ == '__main__':
|
|
|
xy = x[class_member_mask & ~core_samples_mask]
|
|
|
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),
|
|
|
markeredgecolor='k', markersize=6)
|
|
|
+
|
|
|
+ if k != -1:
|
|
|
+ xy = x[class_member_mask]
|
|
|
+ print("cluster %d:" % k)
|
|
|
+ center = np.array([np.average(xy[:, 0]), np.average(xy[:, 1])])
|
|
|
+ print("center = %f, %f" % (center[0], center[1]))
|
|
|
+ center_p = namedtuple("point", "lon lat")(center[0], center[1])
|
|
|
+ rad = 0
|
|
|
+ for loc in xy:
|
|
|
+ p = namedtuple("point", "lon lat")(loc[0], loc[1])
|
|
|
+ rad = max(rad, metric.spherical_distance(center_p, p))
|
|
|
+ rad *= 6400 * 1000
|
|
|
+ print("radius = %f m" % rad)
|
|
|
plt.show()
|