Created
January 6, 2020 16:29
-
-
Save alinazhanguwo/7b77704de7aba9cba70add46aa56e06e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set up the parameters | |
n_init = 12 | |
max_iter = 225 | |
tol = 0.0001 | |
random_state = 42 | |
n_jobs = -1 | |
n_clusters = 3 | |
t0 = dt.now() | |
print("========= Start training ... ") | |
# Initialize the clusterer with n_clusters value and a random generator | |
# seed of 42 for reproducibility. | |
clusterer = KMeans(n_clusters=n_clusters, random_state=random_state) | |
cluster_labels = clusterer.fit_predict(X_train) | |
# inertia | |
inertia = clusterer.inertia_ | |
# The silhouette_score gives the average value for all the samples. | |
# This gives a perspective into the density and separation of the formed | |
# clusters | |
silhouette_avg = silhouette_score(X_train, cluster_labels) | |
# Compute the silhouette scores for each sample | |
sample_silhouette_values = silhouette_samples(X, cluster_labels) | |
print("For n_clusters =", n_clusters, | |
", the inertia is :", inertia, | |
", the average silhouette_score is :", silhouette_avg) | |
t1 = dt.now()-t0 | |
print("========= Finished in ",t1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment