def test_birch_example_reproducibility(example_id):
# check reproducibility of the Birch example
rng = np.random.RandomState(42)
X, y = make_blobs(n_samples=1000, n_features=10, random_state=rng)
cluster_model = Birch(threshold=0.9, branching_factor=20,
compute_sample_indices=True)
cluster_model.fit(X)
#assert len(cluster_model.root_.subclusters_[1].child_.subclusters_) == 3
htree, n_subclusters = birch_hierarchy_wrapper(cluster_model)
assert htree.tree_size == n_subclusters
# same random seed as in the birch hierarchy example
assert htree.tree_size == 78
sc = htree.flatten()[example_id]
if example_id == 34:
# this is true in both cases, but example_id fails on circle ci
assert sc.current_depth == 1
assert len(sc.children) == 3
assert_array_equal([sc['cluster_id'] for sc in htree.flatten()],
np.arange(htree.tree_size))
评论列表
文章目录