Unsupervised learning algorithms analyze data without labeled answers. Why can they find hidden patterns in data?
Think about how the algorithm looks for natural groupings or structures in data without any external guidance.
Unsupervised learning finds hidden patterns by grouping or organizing data points based on their similarities or underlying structures, without needing labeled outputs.
What is the output cluster assignment for the points after running K-means with 2 clusters?
from sklearn.cluster import KMeans import numpy as np points = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]]) kmeans = KMeans(n_clusters=2, random_state=0).fit(points) labels = kmeans.labels_ print(labels.tolist())
Look at how points are grouped by their x-coordinate values.
K-means groups points into clusters based on distance. Points near (1, y) form one cluster (label 0), points near (10, y) form the other (label 1).
You want to reduce the number of features in your dataset while preserving important information. Which unsupervised model is best suited for this?
Think about which method transforms data into fewer dimensions while keeping most variance.
PCA reduces dimensionality by finding new features (principal components) that capture most of the data's variance without labels.
Which metric can be used to evaluate the quality of clusters found by an unsupervised algorithm when no true labels are available?
Look for a metric that measures how well-separated and compact clusters are without needing labels.
Silhouette score measures how similar an object is to its own cluster compared to other clusters, useful without labels.
What error does the following PCA code raise and why?
from sklearn.decomposition import PCA import numpy as np X = np.array([[1, 2], [3, 4], [5, 6]]) pca = PCA(n_components=4) pca.fit(X)
Check the number of components requested versus the shape of the data.
PCA cannot have more components than the smaller dimension of the data (samples or features). Here, n_components=4 is too large for data with shape (3,2).
