cluster_optics_xi#
- sklearn.cluster.cluster_optics_xi(*, reachability, predecessor, ordering, min_samples, min_cluster_size=None, xi=0.05, predecessor_correction=True)#
自动根据Xi-steep方法提取聚类。
- Parameters:
- reachabilityndarray of shape (n_samples,)
OPTICS计算的可达性距离(
reachability_
)。- predecessorndarray of shape (n_samples,)
OPTICS计算的前驱。
- orderingndarray of shape (n_samples,)
OPTICS排序的点索引(
ordering_
)。- min_samplesint > 1 or float between 0 and 1
与提供给OPTICS的min_samples相同。上下陡峭区域不能有超过
min_samples
个连续的非陡峭点。 表示为绝对数或样本数的分数(四舍五入至少为2)。- min_cluster_sizeint > 1 or float between 0 and 1, default=None
OPTICS聚类中最小样本数,表示为绝对数或样本数的分数(四舍五入至少为2)。如果为
None
,则使用min_samples
的值。- xifloat between 0 and 1, default=0.05
确定可达性图上构成聚类边界的最低陡度。例如,可达性图上的上升点定义为从一个点到其后继点的比率最多为1-xi。
- predecessor_correctionbool, default=True
基于计算的前驱修正聚类。
- Returns:
- labelsndarray of shape (n_samples,)
分配给样本的标签。未包含在任何聚类中的点标记为-1。
- clustersndarray of shape (n_clusters, 2)
每个行中以
[start, end]
形式列出的聚类列表,所有索引包括在内。聚类按(end, -start)
(升序)排序,以便较大的聚类包含较小的聚类后出现。由于labels
不反映层次结构,通常len(clusters) > np.unique(labels)
。
Examples
>>> import numpy as np >>> from sklearn.cluster import cluster_optics_xi, compute_optics_graph >>> X = np.array([[1, 2], [2, 5], [3, 6], ... [8, 7], [8, 8], [7, 3]]) >>> ordering, core_distances, reachability, predecessor = compute_optics_graph( ... X, ... min_samples=2, ... max_eps=np.inf, ... metric="minkowski", ... p=2, ... metric_params=None, ... algorithm="auto", ... leaf_size=30, ... n_jobs=None ... ) >>> min_samples = 2 >>> labels, clusters = cluster_optics_xi( ... reachability=reachability, ... predecessor=predecessor, ... ordering=ordering, ... min_samples=min_samples, ... ) >>> labels array([0, 0, 0, 1, 1, 1]) >>> clusters array([[0, 2], [3, 5], [0, 5]])