Question: 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

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 detail ). 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,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 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 points) Repeat Parts 1 and 3 for n_clusters =20 and digits dataset.
Deliverables
Submit a zip file containing your Python code and a "report.pdf" depicting all the plots drawn in the four parts and a paragraph comparing the three methods under different circumstances.
In this assignment, you will use Python's

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!