Created
September 17, 2018 16:49
-
-
Save ImadDabbura/1ad5d599b27d23efae5d284081b531ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Standardize the data | |
| X_std = StandardScaler().fit_transform(df) | |
| # Run local implementation of kmeans | |
| km = Kmeans(n_clusters=2, max_iter=100) | |
| km.fit(X_std) | |
| centroids = km.centroids | |
| # Plot the clustered data | |
| fig, ax = plt.subplots(figsize=(6, 6)) | |
| plt.scatter(X_std[km.labels == 0, 0], X_std[km.labels == 0, 1], | |
| c='green', label='cluster 1') | |
| plt.scatter(X_std[km.labels == 1, 0], X_std[km.labels == 1, 1], | |
| c='blue', label='cluster 2') | |
| plt.scatter(centroids[:, 0], centroids[:, 1], marker='*', s=300, | |
| c='r', label='centroid') | |
| plt.legend() | |
| plt.xlim([-2, 2]) | |
| plt.ylim([-2, 2]) | |
| plt.xlabel('Eruption time in mins') | |
| plt.ylabel('Waiting time to next eruption') | |
| plt.title('Visualization of clustered data', fontweight='bold') | |
| ax.set_aspect('equal'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AttributeError: 'KMeans' object has no attribute 'centroids'