cluster_optics_xi#
- sklearn.cluster.cluster_optics_xi(*, reachability, predecessor, ordering, min_samples, min_cluster_size=None, xi=0.05, predecessor_correction=True)[source]#
根据 Xi 陡峭方法自动提取聚类。
- 参数:
- 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
根据计算出的前驱修正簇。
- 返回:
- labelsndarray of shape (n_samples,)
分配给样本的标签。未包含在任何簇中的点被标记为 -1。
- clustersndarray of shape (n_clusters, 2)
簇列表,每行形式为
[start, end],所有索引均包含在内。簇按(end, -start)(升序)排序,以便包含较小簇的较大簇位于这些嵌套的较小簇之后。由于labels不反映层次结构,通常len(clusters) > np.unique(labels)。
示例
>>> 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]])