Clustering#
thetan.berserker
Thetan Berserker (TB), the main clustering method, and TBSCAN, which links TB centroids with DBSCAN to find non-convex clusters. TB is an alias of berserker.
- thetan.berserker.berserker(points, theta, metric='euclidean')#
Cluster data with Thetan Berserker (TB).
TB finds the number of clusters from a single distance threshold, theta. It runs Thetan Sequential (TS) twice on different random orderings of the data and cleans up spurious centroids after each pass, which makes the result much less sensitive to data order than a single TS pass.
- Parameters:
- pointsndarray, shape (n_samples, n_features)
Data to cluster, as a C-contiguous float64 array.
- thetafloat
Distance threshold. A point joins its nearest centroid when their distance is below theta; otherwise it starts a new cluster. A good value is larger than the biggest cluster diameter and smaller than the smallest gap between clusters.
- metricstr, optional
Distance metric, any name accepted by distance_matrix. The threshold theta is in the units of this metric. Default is ‘euclidean’. ‘dot_prod’ is the negative dot product, so theta is normally negative: theta=-0.9 means a point joins a centroid when their dot product is above 0.9. The dot product also grows with the length of the vectors, so rows are usually normalised to unit length first.
- Returns:
- even_centroids_ex2ndarray, shape (n_clusters, n_features)
Mean of the points in each cluster.
- updated_labels_ex2ndarray, shape (n_samples,)
Cluster index of each point, in the original order of points.
- thetan.berserker.tbscan(X, theta, eps=2.0, min_samples=1)#
Cluster data with TBSCAN (Thetan Berserker followed by DBSCAN).
TB first reduces the data to a small set of centroids. DBSCAN then groups those centroids, which lets TBSCAN find non-linearly separable clusters (rings, moons, spirals) at a fraction of the cost of running DBSCAN on every point.
- Parameters:
- Xndarray, shape (n_samples, n_features)
Data to cluster, as a C-contiguous float64 array.
- thetafloat
Distance threshold passed to berserker. TB always uses the Euclidean metric here.
- epsfloat, optional
DBSCAN neighbourhood radius between TB centroids, in the units of X. Default is 2.0.
- min_samplesint, optional
Number of TB centroids (not points) a DBSCAN neighbourhood needs for its centre to be a core centroid. With the default of 1, every centroid is a core point and no point is labelled as noise.
- Returns:
- centroidsndarray, shape (n_clusters, n_features)
Mean of the TB centroids in each DBSCAN cluster. This is an unweighted mean of centroids, not the mean of the points.
- labelsndarray, shape (n_samples,)
Cluster index of each point, in the original order of X. Points whose TB centroid DBSCAN marks as noise get -1; noise centroids are not included in centroids.