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


Python OPTICS.fit方法代码示例

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


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

示例1: test_auto_extract_hier

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [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_correct_number_of_clusters

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_correct_number_of_clusters():
    # in 'auto' mode

    n_clusters = 3
    X = generate_clustered_data(n_clusters=n_clusters)
    # Parameters chosen specifically for this task.
    # Compute OPTICS
    clust = OPTICS(max_eps=5.0 * 6.0, min_samples=4)
    clust.fit(X)
    # number of clusters, ignoring noise if present
    n_clusters_1 = len(set(clust.labels_)) - int(-1 in clust.labels_)
    assert_equal(n_clusters_1, n_clusters)

    # check attribute types and sizes
    assert clust.core_sample_indices_.ndim == 1
    assert clust.core_sample_indices_.size > 0
    assert clust.core_sample_indices_.dtype.kind == 'i'

    assert clust.labels_.shape == (len(X),)
    assert clust.labels_.dtype.kind == 'i'

    assert clust.reachability_.shape == (len(X),)
    assert clust.reachability_.dtype.kind == 'f'

    assert clust.core_distances_.shape == (len(X),)
    assert clust.core_distances_.dtype.kind == 'f'

    assert clust.ordering_.shape == (len(X),)
    assert clust.ordering_.dtype.kind == 'i'
    assert set(clust.ordering_) == set(range(len(X)))
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:32,代码来源:test_optics.py

示例3: test_bad_reachability

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_bad_reachability():
    msg = "All reachability values are inf. Set a larger max_eps."
    centers = [[1, 1], [-1, -1], [1, -1]]
    X, labels_true = make_blobs(n_samples=750, centers=centers,
                                cluster_std=0.4, random_state=0)

    with pytest.warns(UserWarning, match=msg):
        clust = OPTICS(max_eps=5.0 * 0.003, min_samples=10, eps=0.015)
        clust.fit(X)
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:11,代码来源:test_optics.py

示例4: test_min_cluster_size

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_min_cluster_size(min_cluster_size):
    redX = X[::2]  # reduce for speed
    clust = OPTICS(min_samples=9, min_cluster_size=min_cluster_size).fit(redX)
    cluster_sizes = np.bincount(clust.labels_[clust.labels_ != -1])
    if cluster_sizes.size:
        assert min(cluster_sizes) >= min_cluster_size
    # check behaviour is the same when min_cluster_size is a fraction
    clust_frac = OPTICS(min_samples=9,
                        min_cluster_size=min_cluster_size / redX.shape[0])
    clust_frac.fit(redX)
    assert_array_equal(clust.labels_, clust_frac.labels_)
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:13,代码来源:test_optics.py

示例5: test_correct_number_of_clusters

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_correct_number_of_clusters():
    # in 'auto' mode

    n_clusters = 3
    X = generate_clustered_data(n_clusters=n_clusters)
    # Parameters chosen specifically for this task.
    # Compute OPTICS
    clust = OPTICS(max_bound=5.0 * 6.0, min_samples=4, metric='euclidean')
    clust.fit(X)
    # number of clusters, ignoring noise if present
    n_clusters_1 = len(set(clust.labels_)) - int(-1 in clust.labels_)
    assert_equal(n_clusters_1, n_clusters)
开发者ID:as133,项目名称:scikit-learn,代码行数:14,代码来源:test_optics.py

示例6: test_optics

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_optics():
    # Tests the optics clustering method and all functions inside it
    # 'auto' mode

    n_clusters = 3
    X = generate_clustered_data(n_clusters=n_clusters)
    print(np.shape(X))
    # Parameters chosen specifically for this task.
    # Compute OPTICS
    clust = OPTICS(eps=6.0, min_samples=4, metric='euclidean')
    clust.fit(X)
    # number of clusters, ignoring noise if present
    n_clusters_1 = len(set(clust.labels_)) - int(-1 in clust.labels_)
    assert_equal(n_clusters_1, n_clusters)
开发者ID:,项目名称:,代码行数:16,代码来源:

示例7: test_bad_extract

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_bad_extract():
    # Test an extraction of eps too close to original eps
    msg = "Specify an epsilon smaller than 0.15. Got 0.3."
    centers = [[1, 1], [-1, -1], [1, -1]]
    X, labels_true = make_blobs(n_samples=750, centers=centers,
                                cluster_std=0.4, random_state=0)

    # Compute OPTICS
    clust = OPTICS(max_eps=5.0 * 0.03, min_samples=10)
    clust2 = clust.fit(X)
    assert_raise_message(ValueError, msg, clust2.extract_dbscan, 0.3)
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:13,代码来源:test_optics.py

示例8: test_filter

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [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,代码来源:

示例9: test_close_extract

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_close_extract():
    # Test extract where extraction eps is close to scaled epsPrime

    centers = [[1, 1], [-1, -1], [1, -1]]
    X, labels_true = make_blobs(n_samples=750, centers=centers,
                                cluster_std=0.4, random_state=0)

    # Compute OPTICS

    clust = OPTICS(eps=0.2, min_samples=10)
    clust3 = clust.fit(X)
    clust3.extract(0.3, clustering='dbscan')
    assert max(clust3.labels_) == 3
开发者ID:,项目名称:,代码行数:15,代码来源:

示例10: test_bad_extract

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_bad_extract():
    # Test an extraction of eps too close to original eps

    centers = [[1, 1], [-1, -1], [1, -1]]
    X, labels_true = make_blobs(n_samples=750, centers=centers,
                                cluster_std=0.4, random_state=0)

    ##########################################################################
    # Compute OPTICS

    clust = OPTICS(eps=0.003, min_samples=10)
    clust2 = clust.fit(X)
    assert clust2.extract(0.3) is None
开发者ID:,项目名称:,代码行数:15,代码来源:

示例11: test_optics2

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_optics2():
    # Tests the optics clustering method and all functions inside it
    # 'dbscan' mode

    # Compute OPTICS
    X = [[1, 1]]
    clust = OPTICS(eps=0.3, min_samples=10)

    # Run the fit

    clust2 = clust.fit(X)

    assert clust2 is None
开发者ID:,项目名称:,代码行数:15,代码来源:

示例12: test_close_extract

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_close_extract():
    # Test extract where extraction eps is close to scaled epsPrime

    centers = [[1, 1], [-1, -1], [1, -1]]
    X, labels_true = make_blobs(n_samples=750, centers=centers,
                                cluster_std=0.4, random_state=0)

    # Compute OPTICS
    clust = OPTICS(max_eps=1.0, min_samples=10)
    clust3 = clust.fit(X)
    # check warning when centers are passed
    assert_warns(RuntimeWarning, clust3.extract_dbscan, .3)
    # Cluster ordering starts at 0; max cluster label = 2 is 3 clusters
    assert_equal(max(clust3.extract_dbscan(.3)[1]), 2)
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:16,代码来源:test_optics.py

示例13: test_auto_extract_hier

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_auto_extract_hier():
    # Tests auto extraction gets correct # of clusters with varying density

    # Generate sample data
    rng = np.random.RandomState(0)
    n_points_per_cluster = 250

    C1 = [-5, -2] + .8 * rng.randn(n_points_per_cluster, 2)
    C2 = [4, -1] + .1 * rng.randn(n_points_per_cluster, 2)
    C3 = [1, -2] + .2 * rng.randn(n_points_per_cluster, 2)
    C4 = [-2, 3] + .3 * rng.randn(n_points_per_cluster, 2)
    C5 = [3, -2] + 1.6 * rng.randn(n_points_per_cluster, 2)
    C6 = [5, 6] + 2 * rng.randn(n_points_per_cluster, 2)
    X = np.vstack((C1, C2, C3, C4, C5, C6))

    # Compute OPTICS

    clust = OPTICS(min_samples=9)

    # Run the fit
    clust.fit(X)

    assert_equal(len(set(clust.labels_)), 6)
开发者ID:as133,项目名称:scikit-learn,代码行数:25,代码来源:test_optics.py

示例14: test_min_cluster_size_invalid2

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_min_cluster_size_invalid2():
    clust = OPTICS(min_cluster_size=len(X) + 1)
    with pytest.raises(ValueError, match="must be no greater than the "):
        clust.fit(X)
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:6,代码来源:test_optics.py

示例15: test_min_cluster_size_invalid

# 需要导入模块: from sklearn.cluster.optics_ import OPTICS [as 别名]
# 或者: from sklearn.cluster.optics_.OPTICS import fit [as 别名]
def test_min_cluster_size_invalid(min_cluster_size):
    clust = OPTICS(min_cluster_size=min_cluster_size)
    with pytest.raises(ValueError, match="must be a positive integer or a "):
        clust.fit(X)
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:6,代码来源:test_optics.py


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