How to use the yellowbrick.cluster.KElbowVisualizer function in yellowbrick

To help you get started, we’ve selected a few yellowbrick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DistrictDataLabs / yellowbrick / docs / gallery.py View on Github external
def elbow():
    X, _ = make_blobs(centers=8, n_features=12, shuffle=True)
    oz = KElbowVisualizer(KMeans(), k=(4, 12), ax=newfig())
    oz.fit(X)
    savefig(oz, "elbow")
github DistrictDataLabs / yellowbrick / docs / images / readme / readme_imgs.py View on Github external
def k_elbow(ax=None):
    X, y = make_blobs(centers=12, n_samples=1000, n_features=16, shuffle=True)

    viz = KElbowVisualizer(KMeans(), k=(4, 12), ax=ax, locate_elbow=False)
    viz.fit(X)
    viz.finalize()

    return viz
github Ashton-Sidhu / aethos / aethos / modelling / unsupervised_models.py View on Github external
def find_optk():

            from yellowbrick.cluster import KElbowVisualizer

            model = KMeans(**kwargs)

            visualizer = KElbowVisualizer(model, k=(4, 12))
            visualizer.fit(self.train_data)
            visualizer.show()

            print(f"Optimal number of clusters is {visualizer.elbow_value_}.")

            return visualizer.elbow_value_
github DistrictDataLabs / yellowbrick / docs / api / cluster / elbow.py View on Github external
def draw_elbow(path="images/elbow.png"):
    # Generate synthetic dataset with 8 blobs
    X, y = make_blobs(
        centers=8, n_features=12, n_samples=1000,
        shuffle=True, random_state=42
    )

    # Create a new figure to draw the clustering visualizer on
    _, ax = plt.subplots()

    # Instantiate the clustering model and visualizer
    model = KMeans()
    visualizer = KElbowVisualizer(model, ax=ax, k=(4,12))

    visualizer.fit(X)                # Fit the data to the visualizer
    visualizer.poof(outpath=path)    # Draw/show/poof the data
github DistrictDataLabs / yellowbrick / paper / figures / figures.py View on Github external
def clustering(fname="clustering.png"):
    # Create side-by-side axes grid
    _, axes = plt.subplots(ncols=2, figsize=(18,6))
    X, y = make_blobs(centers=7)

    # Add K-Elbow to the left
    oz = KElbowVisualizer(MiniBatchKMeans(), k=(3,12), ax=axes[0])
    oz.fit(X, y)
    oz.finalize()

    # Add SilhouetteVisualizer to the right
    oz = SilhouetteVisualizer(Birch(n_clusters=5), ax=axes[1])
    oz.fit(X, y)
    oz.finalize()

    # Save figure
    path = os.path.join(FIGURES, fname)
    plt.tight_layout()
    plt.savefig(path)
github DistrictDataLabs / yellowbrick / docs / api / cluster / elbow.py View on Github external
def draw_calinski_harabaz(path="images/calinski_harabaz.png"):
    # Generate synthetic dataset with 8 blobs
    X, y = make_blobs(
        centers=8, n_features=12, n_samples=1000,
        shuffle=True, random_state=42
    )

    # Create a new figure to draw the clustering visualizer on
    _, ax = plt.subplots()

    # Instantiate the clustering model and visualizer
    model = KMeans()
    visualizer = KElbowVisualizer(
        model, ax=ax, k=(4,12),
        metric='calinski_harabaz', timings=False
    )
    visualizer.fit(X)                # Fit the data to the visualizer
    visualizer.poof(outpath=path)    # Draw/show/poof the data