Final answer:
To perform K-Means clustering on datasets 1 and 2, choose a value for K (e.g., 2), apply the algorithm using Python's sklearn library, and obtain the cluster centers and labels for each dataset.
Step-by-step explanation:
Applying K-Means Clustering Algorithm: Let's say we choose K=2 for the purpose of this example. The following are the general steps for K-Means:
- Randomly initialize two centers for the two clusters.
- Assign each data point to the nearest cluster center.
- Recompute the cluster centers based on the mean of the assigned points.
- Repeat steps 2 and 3 until the cluster centers do not change significantly or a maximum number of iterations is reached.
Using Python, here is a simple implementation for dataset 1:
from sklearn.cluster import KMeans
# Dataset1
X1 = [[5], [8], [21], [6], [24], [23]]
# Apply KMeans
kmeans1 = KMeans(n_clusters=2, random_state=0).fit(X1)
print("Cluster centers:", kmeans1.cluster_centers_)
print("Labels:", kmeans1.labels_)
As for dataset 2, the implementation would look like this:
# Dataset2
X2 = [(1,2), (1,3), (2,2), (3,2), (3,4), (3,3)]
# Apply KMeans
kmeans2 = KMeans(n_clusters=2, random_state=0).fit(X2)
print("Cluster centers:", kmeans2.cluster_centers_)
print("Labels:", kmeans2.labels_)