def clustering(X, algorithm, n_clusters):
    X = StandardScaler().fit_transform(X)
    bandwidth = cluster.estimate_bandwidth(X, quantile=0.3)
    connectivity = kneighbors_graph(X, n_neighbors=10, include_self=False)
    connectivity = (0.5 * (connectivity + connectivity.T))
    if (algorithm == 'MiniBatchKMeans'):
        model = cluster.MiniBatchKMeans(n_clusters=n_clusters)
    elif (algorithm == 'Birch'):
        model = cluster.Birch(n_clusters=n_clusters)
    elif (algorithm == 'DBSCAN'):
        model = cluster.DBSCAN(eps=0.2)
    elif (algorithm == 'AffinityPropagation'):
        model = cluster.AffinityPropagation(damping=0.9, preference=(- 200))
    elif (algorithm == 'MeanShift'):
        model = cluster.MeanShift(bandwidth=bandwidth, bin_seeding=True)
    elif (algorithm == 'SpectralClustering'):
        model = cluster.SpectralClustering(n_clusters=n_clusters, eigen_solver='arpack', affinity='nearest_neighbors')
    elif (algorithm == 'Ward'):
        model = cluster.AgglomerativeClustering(n_clusters=n_clusters, linkage='ward', connectivity=connectivity)
    elif (algorithm == 'AgglomerativeClustering'):
        model = cluster.AgglomerativeClustering(linkage='average', affinity='cityblock', n_clusters=n_clusters, connectivity=connectivity)
    model.fit(X)
    if hasattr(model, 'labels_'):
        y_pred = model.labels_.astype(np.int)
    else:
        y_pred = model.predict(X)
    return (X, y_pred)
def clustering(X, algorithm, n_clusters):
    X = StandardScaler().fit_transform(X)
    bandwidth = cluster.estimate_bandwidth(X, quantile=0.3)
    connectivity = kneighbors_graph(X, n_neighbors=10, include_self=False)
    connectivity = (0.5 * (connectivity + connectivity.T))
    if (algorithm == 'MiniBatchKMeans'):
        model = cluster.MiniBatchKMeans(n_clusters=n_clusters)
    elif (algorithm == 'Birch'):
        model = cluster.Birch(n_clusters=n_clusters)
    elif (algorithm == 'DBSCAN'):
        model = cluster.DBSCAN(eps=0.2)
    elif (algorithm == 'AffinityPropagation'):
        model = cluster.AffinityPropagation(damping=0.9, preference=(- 200))
    elif (algorithm == 'MeanShift'):
        model = cluster.MeanShift(bandwidth=bandwidth, bin_seeding=True)
    elif (algorithm == 'SpectralClustering'):
        model = cluster.SpectralClustering(n_clusters=n_clusters, eigen_solver='arpack', affinity='nearest_neighbors')
    elif (algorithm == 'Ward'):
        model = cluster.AgglomerativeClustering(n_clusters=n_clusters, linkage='ward', connectivity=connectivity)
    elif (algorithm == 'AgglomerativeClustering'):
        model = cluster.AgglomerativeClustering(linkage='average', affinity='cityblock', n_clusters=n_clusters, connectivity=connectivity)
    model.fit(X)
    if hasattr(model, 'labels_'):
        y_pred = model.labels_.astype(np.int)
    else:
        y_pred = model.predict(X)
    return (X, y_pred)