Exemple #1
0
def intercluster_distance(ax=None):
    X, y = make_blobs(centers=12, n_samples=1000, n_features=16, shuffle=True)

    viz = InterclusterDistance(KMeans(9), ax=ax)
    viz.fit(X)
    viz.finalize()

    return viz
def distance_yellowbrick(
    X,
    y,
    features,
):
    plt.switch_backend('agg')
    plt.clf()
    X_train, X_test, y_train, y_test = train_test_split(X[features],
                                                        y,
                                                        stratify=y,
                                                        test_size=0.01)
    X = pd.DataFrame(X_test, columns=features)
    y = pd.Series(y_test)
    n_clusters = y.nunique()
    model = MiniBatchKMeans(n_clusters)
    visualizer_dist = InterclusterDistance(model)
    visualizer_dist.fit(X)
    visualizer_dist.finalize()

    return plt