alexanderholt
11/14/2017 - 7:35 PM

Mini Batch K Means Function

#I'm going to make this simple by writing a function to do this for different numbers of K
def cluster_batch(k, data=x_df):
    k_mean = MiniBatchKMeans(n_clusters = k)
    fitted = k_mean.fit(data)
    labels = fitted.labels_
    print(labels)
    print("Labels: " + str(labels))
    print("Centroids: " + str(fitted.cluster_centers_))
    print("Silhouette Score: " + str(silhouette_score(data, labels,sample_size=int(data.shape[0]*.1))))
    print("Silhouette Score: " + str(silhouette_score(data, labels,sample_size=int(data.shape[0]*.2))))
    print("Silhouette Score: " + str(silhouette_score(data, labels,sample_size=int(data.shape[0]*.3))))