Data Science with Python Certification Data Science with Python Unsupervised Learning Algorithms 4 — Questions and Answers
Question 1: Which of the following is NOT a valid initialization strategy for K-Means in scikit-learn?
- 'ward' (Correct answer)
- 'k-means++'
- 'random'
- a numpy array of initial centroids
Correct answer: 'ward'
'ward' is a linkage criterion for hierarchical clustering, not a valid `init` parameter for `KMeans`.
Question 2: What does the Calinski-Harabasz index measure?
- The ratio of between-cluster dispersion to within-cluster dispersion (Correct answer)
- The sum of squared distances to cluster centers
- The probability of cluster membership
- The number of noise points in DBSCAN
Correct answer: The ratio of between-cluster dispersion to within-cluster dispersion
A higher Calinski-Harabasz index indicates denser, well-separated clusters.
Question 3: In Isolation Forest, how are anomalies detected?
- Anomalies are isolated in fewer splits than normal points (Correct answer)
- Anomalies have the highest density in random subspaces
- Anomalies are points far from cluster centroids
- Anomalies are identified by negative eigenvalues
Correct answer: Anomalies are isolated in fewer splits than normal points
Isolation Forest isolates anomalies using random partitioning trees; anomalies require fewer splits because they differ from most points.
Question 4: What is the main advantage of using sparse PCA over standard PCA?
- Sparse PCA produces components with few non-zero loadings, improving interpretability (Correct answer)
- Sparse PCA is faster on all datasets
- Sparse PCA always retains more variance
- Sparse PCA works only on categorical data
Correct answer: Sparse PCA produces components with few non-zero loadings, improving interpretability
Sparse PCA introduces sparsity constraints so each component depends on only a few original features, aiding interpretation.
Question 5: Which algorithm is best suited for clustering data with non-convex shapes?
- DBSCAN (Correct answer)
- K-Means
- Gaussian Mixture Model
- PCA
Correct answer: DBSCAN
DBSCAN identifies clusters based on density, making it capable of finding arbitrarily shaped clusters.
Question 6: In the context of autoencoders used for unsupervised learning, what is the 'bottleneck'?
- The hidden layer with the fewest neurons that forms the compressed representation (Correct answer)
- The output layer that reconstructs the input
- The loss function used during training
- The regularization term added to prevent overfitting
Correct answer: The hidden layer with the fewest neurons that forms the compressed representation
The bottleneck layer forces the autoencoder to learn a compact latent representation of the input data.
Question 7: When using `sklearn.decomposition.PCA`, what does `explained_variance_ratio_` return?
- The fraction of total variance explained by each principal component (Correct answer)
- The eigenvalues of the covariance matrix
- The number of components needed for 95% variance
- The cumulative variance across all components
Correct answer: The fraction of total variance explained by each principal component
`explained_variance_ratio_` gives the proportion of variance explained by each component as a numpy array.
Which of the following is NOT a valid initialization strategy for K-Means in scikit-learn?