Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
indices : array
Indices that sort the computed mean distances.
mdist : array
Mean distance characterizing each data sample.
"""
if metric_args is None:
metric_args = {}
# compute distances
D = metrics.pdist(data, metric=metric, **metric_args)
D = metrics.squareform(D)
# compute mean
mdist = np.mean(D, axis=0)
# sort
indices = np.argsort(mdist)
return indices, mdist
“A Density-Based Algorithm for Discovering Clusters in Large Spatial
Databases with Noise”, Proceedings of the 2nd International
Conf. on Knowledge Discovery and Data Mining, pp. 226-231, 1996.
"""
# check inputs
if data is None:
raise TypeError("Please specify input data.")
if metric_args is None:
metric_args = {}
# compute distances
D = metrics.pdist(data, metric=metric, **metric_args)
D = metrics.squareform(D)
# fit
db = skc.DBSCAN(eps=eps, min_samples=min_samples, metric='precomputed')
labels = db.fit_predict(D)
# get cluster indices
clusters = _extract_clusters(labels)
return utils.ReturnTuple((clusters,), ('clusters',))
raise TypeError("Please specify the input co-association matrix.")
if linkage not in ['average', 'complete', 'single', 'weighted']:
raise ValueError("Unknown linkage criterion '%r'." % linkage)
N = len(coassoc)
if k > N:
raise ValueError("Number of clusters 'k' is higher than the number of \
input samples.")
if k < 0:
k = 0
# convert coassoc to condensed format, dissimilarity
mx = np.max(coassoc)
D = metrics.squareform(mx - coassoc)
# build linkage
Z = sch.linkage(D, method=linkage)
# extract clusters
if k == 0:
# life-time
labels = _life_time(Z, N)
else:
labels = sch.fcluster(Z, k, 'maxclust')
# get cluster indices
clusters = _extract_clusters(labels)
return utils.ReturnTuple((clusters,), ('clusters',))