apply three main clustering methods k-means, density-based, and hierarchical methods on different toy datasets
In this assignment, you will use Python’s sklearn.cluster package and three of its tools called “KMeans”, “DBSCAN”, and “AgglomerativeClustering” to apply three main clustering methods k-means, density-based, and hierarchical methods on different toy datasets of Python SKLearn (see here for more detailLinks to an external site.). You can watch the video illustrating some of the Python tools that you need for this assignment:
Part 1: k-means clustering (25 points):
Load breast cancer dataset (by calling sklearn.datasets.load_breast_cancer)
data = load_breast_cancer().data
Since the dataset has 30 different features, use the following code to reduce the dimensions of the dataset to 2 features (as we will later plot the observations using 2D scatter plots, this is a necessary step!):
from sklearn.decomposition import PCA
pca = PCA(2)
df = pca.fit_transform(data)
Create an object of sklearn.cluster.KMeans class with n_clusters = 10.
- kmeans = KMeans(n_clusters = 10)
Fit and predict the transformed dataset df:
- label = kmeans.fit_predict(df)
Use matplotlib.pyplot to plot all the observations on a 2D coordinate system. Color observations of each cluster with a different color:
import matplotlib.pyplot as plt
for i in range(10):
- plt.scatter(df[label == i , 0] , df[label == i , 1] , label = i)
plt.legend()
- plt.show()
Part 2 (25 points): Repeat Part I for digits dataset (use load_digits() instead). Use density-based clustering (use DBSCAN(min_samples = 10, eps = 1.5) instead of KMeans(n_clusters = 10)). Draw the plot for labels 0, 1, 2, …, 22
Part 3 (25 points): Repeat Part I for iris dataset (use load_iris() instead). Use hierarchical clustering with 5 clusters (use AgglomerativeClustering(n_clusters = 5) instead of KMeans(n_clusters = 10))
- Part 4 (25 points) Repeat Parts 1 and 3 for n_clusters = 20 and digits dataset.
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.