Data Science with Python Unsupervised Learning Algorithms Questions and Answers — Questions and Answers
Question 1: A retail company wants to segment its customer base into distinct groups based on purchasing behavior (e.g., purchase frequency, monetary value, items purchased) to tailor marketing campaigns. The company does not have any predefined labels for these customer groups. Which of the following algorithms is most appropriate for this task?
- Logistic Regression
- Linear Regression
- K-Means Clustering (Correct answer)
- A/B Testing
Correct answer: K-Means Clustering
K-Means is an unsupervised clustering algorithm ideal for partitioning a dataset into a specified number of distinct, non-overlapping subgroups (clusters) without prior knowledge of the group labels. [9] This scenario, known as customer segmentation, is a classic use case for clustering, as the goal is to discover natural groupings in the data. [24]
Question 2: What is the primary objective of the Principal Component Analysis (PCA) algorithm?
- To group similar data points into a specified number of clusters.
- To reduce the dimensionality of a dataset while preserving the maximum amount of variance. (Correct answer)
- To predict a continuous target variable based on one or more predictor variables.
- To find the optimal set of hyperparameters for a machine learning model.
Correct answer: To reduce the dimensionality of a dataset while preserving the maximum amount of variance.
Principal Component Analysis (PCA) is a dimensionality reduction technique used to transform a large set of variables into a smaller one that still contains most of the information. [11] It achieves this by identifying a new set of uncorrelated variables, called principal components, that are ordered by the amount of variance they explain in the original data. [23, 5]
Question 3: A data scientist is using the K-Means algorithm and needs to configure its parameters. Which of the following is a mandatory hyperparameter that must be specified *before* running the algorithm?
- The epsilon (ε) neighborhood distance
- The linkage criterion
- The number of clusters (K) (Correct answer)
- The number of principal components
Correct answer: The number of clusters (K)
The K-Means algorithm requires the user to specify the number of clusters, represented by 'K', before it can begin partitioning the data. [14, 25] The algorithm then iteratively assigns data points to the nearest of these K centroids. The other options are hyperparameters for different algorithms: epsilon for DBSCAN, linkage criterion for Hierarchical Clustering, and the number of components for PCA.
Question 4: A cybersecurity analyst is processing a large dataset of network traffic to identify novel, previously unseen types of attacks (zero-day exploits). These attacks would appear as unusual patterns distinct from the vast amount of normal traffic. Which unsupervised learning task is most suitable for this scenario?
- Dimensionality Reduction
- Anomaly Detection (Correct answer)
- Association Rule Mining
- Regression
Correct answer: Anomaly Detection
Anomaly detection is the ideal task for this scenario. Unsupervised anomaly detection models are trained on data representing normal behavior and are designed to identify data points or patterns that deviate significantly from this norm. [12] This makes them effective at detecting unknown attacks without needing pre-labeled examples of those attacks. [7, 18]
Question 5: Which of the following clustering algorithms is particularly well-suited for discovering clusters of arbitrary shapes and is robust to outliers, which it can identify as noise?
- K-Means
- DBSCAN (Density-Based Spatial Clustering of Applications with Noise) (Correct answer)
- Principal Component Analysis (PCA)
- Linear Regression
Correct answer: DBSCAN (Density-Based Spatial Clustering of Applications with Noise)
DBSCAN is a density-based clustering algorithm that excels at finding clusters of non-spherical or arbitrary shapes. [1, 10] A key advantage of DBSCAN over algorithms like K-Means is its ability to identify points that do not belong to any cluster, labeling them as noise or outliers, making it highly robust. [8]
Question 6: In agglomerative hierarchical clustering, what is the purpose of the 'linkage criterion' (e.g., 'ward', 'complete', 'average')?
- To determine the initial number of clusters.
- To specify the distance metric used to calculate the space between individual data points.
- To define how the distance between two clusters is measured in order to decide which clusters to merge. (Correct answer)
- To set the threshold for cutting the dendrogram to form the final clusters.
Correct answer: To define how the distance between two clusters is measured in order to decide which clusters to merge.
The linkage criterion in hierarchical clustering specifies how the dissimilarity between clusters is measured. [17] For example, 'complete' linkage uses the maximum distance between points in two clusters, while 'single' linkage uses the minimum distance. [6, 29] This criterion is fundamental to the algorithm's bottom-up approach of successively merging the closest pair of clusters.
A retail company wants to segment its customer base into distinct groups based on purchasing behavior (e.g., purchase frequency, monetary value, items purchased) to tailor marketing campaigns.
The company does not have any predefined labels for these customer groups.
Which of the following algorithms is most appropriate for this task?