当前位置: 首页>>代码示例>>Python>>正文


Python OPTICS.extract方法代码示例

本文整理汇总了Python中sklearn.cluster.optics_.OPTICS.extract方法的典型用法代码示例。如果您正苦于以下问题:Python OPTICS.extract方法的具体用法?Python OPTICS.extract怎么用?Python OPTICS.extract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.cluster.optics_.OPTICS的用法示例。


在下文中一共展示了OPTICS.extract方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_auto_extract_hier

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import extract [as 别名]
def test_auto_extract_hier():
    # Generate sample data

    np.random.seed(0)
    n_points_per_cluster = 250

    X = np.empty((0, 2))
    X = np.r_[X, [-5, -2] + .8 * np.random.randn(n_points_per_cluster, 2)]
    X = np.r_[X, [4, -1] + .1 * np.random.randn(n_points_per_cluster, 2)]
    X = np.r_[X, [1, -2] + .2 * np.random.randn(n_points_per_cluster, 2)]
    X = np.r_[X, [-2, 3] + .3 * np.random.randn(n_points_per_cluster, 2)]
    X = np.r_[X, [3, -2] + 1.6 * np.random.randn(n_points_per_cluster, 2)]
    X = np.r_[X, [5, 6] + 2 * np.random.randn(n_points_per_cluster, 2)]

    # Compute OPTICS

    clust = OPTICS(eps=30.3, min_samples=9)

    # Run the fit
    clust.fit(X)

    # Extract the result
    # eps not used for 'auto' extract
    clust.extract(0.0, 'auto')

    assert_equal(len(set(clust.labels_)), 6)
开发者ID:,项目名称:,代码行数:28,代码来源:

示例2: test_filter

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import extract [as 别名]
def test_filter():
    # Tests the filter function.

    n_clusters = 3
    X = generate_clustered_data(n_clusters=n_clusters)
    # Parameters chosen specifically for this task.
    clust = OPTICS(eps=6.0, min_samples=4, metric='euclidean')
    # Run filter (before computing OPTICS)
    bool_memb = clust.filter(X, 0.5)
    idx_memb = clust.filter(X, 0.5, index_type='idx')
    # Test for equivalence between 'idx' and 'bool' extraction
    assert_equal(sum(bool_memb), len(idx_memb))
    # Compute OPTICS
    clust.fit(X)
    clust.extract(0.5, clustering='dbscan')
    # core points from filter and extract should be the same within 1 point,
    # with extract occasionally underestimating due to start point of the
    # OPTICS algorithm. Here we test for at least 95% similarity in
    # classification of core/not core
    agree = sum(clust._is_core == bool_memb)
    assert_greater_equal(float(agree)/len(X), 0.95)
开发者ID:,项目名称:,代码行数:23,代码来源:

示例3: set

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import extract [as 别名]
    plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
             markeredgecolor='k', markersize=14, alpha=0.5)

    xy = X[class_member_mask & ~core_samples_mask]
    plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
             markeredgecolor='k', markersize=2, alpha=0.5)

plt.title("Automatic Clustering \n Estimated number of clusters: %d"
          % clust.n_clusters)

# (Re)-extract clustering structure, using a single eps to show comparison
# with DBSCAN. This can be run for any clustering distance, and can be run
# multiple times without rerunning OPTICS. OPTICS does need to be re-run to c
# hange the min-pts parameter.

clust.extract(.15, 'dbscan')

core_samples_mask = np.zeros_like(clust.labels_, dtype=bool)
core_samples_mask[clust.core_sample_indices_] = True

# Black removed and is used for noise instead.
unique_labels = set(clust.labels_)
colors = plt.cm.Spectral(np.linspace(0, 1, len(unique_labels)))

plt.subplot(223)

for k, col in zip(unique_labels, colors):
    if k == -1:
        # Black used for noise.
        col = 'k'
开发者ID:,项目名称:,代码行数:32,代码来源:

示例4: test_empty_extract

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import extract [as 别名]
def test_empty_extract():
    # Test extract where fit() has not yet been run.

    clust = OPTICS(eps=0.3, min_samples=10)
    assert clust.extract(0.01, clustering='auto') is None
开发者ID:,项目名称:,代码行数:7,代码来源:


注:本文中的sklearn.cluster.optics_.OPTICS.extract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。