コード例 #1
0
def main():
    random_state = 111

    X, y = make_circles(n_samples=1000, random_state=random_state, noise=0.07)

    window = (X > 0).all(axis=1)
    X_window = X[window]
    y_window = y[window]

    spk = SuperK(k=5)

    spk.load_data(X_window, y_window)

    figsize = (5, 5)

    vox_genpts = spk.voxelize()
    spk.genpts = np.vstack([class_genpts for _, class_genpts in vox_genpts])
    spk.genpts_labels = np.hstack([
        np.full(len(class_genpts), class_inx)
        for class_inx, class_genpts in vox_genpts
    ])
    plot_boundaries(spk, "voxelized", figsize)

    em_genpts = spk.apply_em(vox_genpts)
    spk.genpts = np.vstack([class_genpts for _, class_genpts in em_genpts])
    spk.genpts_labels = np.hstack([
        np.full(len(class_genpts), class_inx)
        for class_inx, class_genpts in em_genpts
    ])
    plot_boundaries(spk, "after_em", figsize)

    spk.genpts, spk.genpts_labels = spk.merge_and_label(em_genpts)
    plot_boundaries(spk, "relabeled", figsize)

    spk.correct()
    plot_boundaries(spk, "corrected", figsize)
コード例 #2
0
ファイル: test_moons.py プロジェクト: ituamg/super-klust
def main():
    random_state = 111

    X, y = make_moons(n_samples=1000, random_state=random_state, noise=0.15)

    figsize = (4, 2.75)

    spk = SuperKlust(k=2, kmns_n_init=3)
    spk.fit(X, y)
    plot_boundaries(spk, "moons_1", figsize)

    spk = SuperKlust(k=4, kmns_n_init=3)
    spk.fit(X, y)
    plot_boundaries(spk, "moons_2", figsize)

    spk = SuperKlust(k=6, kmns_n_init=3)
    spk.fit(X, y)
    plot_boundaries(spk, "moons_3", figsize)
コード例 #3
0
ファイル: test_circles.py プロジェクト: ituamg/super-k
def main():
    random_state = 111

    X, y = make_circles(n_samples=1000, random_state=random_state, noise=0.05)

    figsize = (4, 4.5)

    spk = SuperK(k=10)
    spk.fit(X, y)
    plot_boundaries(spk, "circles_1", figsize)

    spk = SuperK(k=20)
    spk.fit(X, y)
    plot_boundaries(spk, "circles_2", figsize)

    spk = SuperK(k=30)
    spk.fit(X, y)
    plot_boundaries(spk, "circles_3", figsize)
コード例 #4
0
def main():
    random_state = 6

    X, y = make_classification(n_samples=1000,
                               n_classes=3,
                               n_features=2,
                               n_redundant=0,
                               n_informative=2,
                               n_clusters_per_class=1,
                               random_state=random_state)

    figsize = (4, 5.25)

    spk = SuperK(k=2)
    spk.fit(X, y)
    plot_boundaries(spk, "random_1", figsize)

    spk = SuperK(k=5)
    spk.fit(X, y)
    plot_boundaries(spk, "random_2", figsize)

    spk = SuperK(k=8)
    spk.fit(X, y)
    plot_boundaries(spk, "random_3", figsize)