Data Science Ex3

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/67

encourage image

There are no tags or description

Looks like no tags are added yet.

68 Terms

1
New cards

[Q1 - Part 1] Clustering vs Classification

Classification is supervised, assigning observations to predefined known class labels using a model trained on labeled data; clustering is unsupervised, discovering natural groupings in unlabeled data based solely on intrinsic feature similarity.

2
New cards

[Q1 - Part 1] Intra-Cluster Similarity Cohesion

A property of a useful clustering result where points within the same cluster are closely grouped together.

3
New cards

[Q1 - Part 1] Inter-Cluster Similarity Separation

A property of a useful clustering result where different clusters are well separated and distinct from one another.

4
New cards

[Q1 - Part 2] Davies-Bouldin Index Definition

An internal validation metric using dataset feature distances, measuring average worst-case ratio of within-cluster scatter to between-cluster separation; lower is better, used when ground-truth labels are unavailable.

5
New cards

[Q1 - Part 2] Adjusted Rand Index Definition

An external validation metric measuring agreement between predicted cluster assignments and true class labels, corrected for chance, up to 1.0; higher is better, used when ground-truth labels are available.

6
New cards

[Q1 - Part 2] Comparing Internal and External Validation

Internal validation metrics like DBI rely solely on intrinsic feature geometry without labels, while external validation metrics like ARI require ground-truth class labels to benchmark cluster quality.

7
New cards

[Q2 - Part 1] K-Means Main Operations

Assignment step: assign each point to the cluster with the closest centroid using Euclidean distance. Update step: recompute each centroid as the coordinate-wise mean of assigned points.

8
New cards

[Q2 - Part 1] K-Means Stopping Condition

The algorithm stops when cluster assignments no longer change between iterations, indicating that centroids have stabilized.

9
New cards

[Q2 - Part 2] Elbow Method Procedure

Compute the drop in SSE between consecutive K values, identify where large drops stop and reductions flatten into a bend, and justify the choice using those drops without stating the final K.

10
New cards

[Q2 - Part 2] Limitation of the Elbow Method

The elbow is subjective and often ambiguous when SSE decreases smoothly with no distinct bend, or when clusters are non-spherical or overlapping.

11
New cards

[Q2 - Part 3] Iteration 1 Assignment Procedure

Compute Euclidean distance from each point to each current centroid, assign to the nearer one, and apply the tie-rule where ties go to the centroid with the lower point number.

12
New cards

[Q2 - Part 3] Centroid Update Procedure

Average the x-values and the y-values of all points currently assigned to each cluster to determine updated centroid coordinates.

13
New cards

[Q2 - Part 3] Iteration Repetition Procedure

Repeat assignment and update steps iteratively until cluster assignments remain unchanged between consecutive iterations.

14
New cards

[Q2 - Part 3] Recognizing Convergence Concept

Convergence is recognized because the assignments in the latest iteration are identical to the previous one, so the centroids no longer move.

15
New cards

[Q2 - Part 3] Final SSE Calculation Method

Formula SSE = sum over clusters of sum over points of squared distance to that cluster's centroid. Steps: compute each point's squared distance to its final centroid, sum within each cluster, then sum across clusters.

16
New cards

[Q3 - Part 1] Agglomerative Clustering Procedure

Repeatedly find the smallest off-diagonal distance in the current distance matrix and merge that pair at that height.

17
New cards

[Q3 - Part 1] Updating Matrix Under Complete Linkage

Distance from a merged cluster to any other cluster equals the maximum of the member-to-member distances, then drop old rows/columns and add the new cluster.

18
New cards

[Q3 - Part 1] Complete Linkage Repetition

Repeat matrix updates and merges until only one cluster remains, with the final merge height equal to the last remaining matrix entry.

19
New cards

[Q3 - Part 1] Drawing the Dendrogram Procedure

Place leaves at height 0 and draw each merge as a horizontal bracket at its corresponding merge height.

20
New cards

[Q3 - Part 1] Interpreting the Two-Cluster Cut

Cut the dendrogram between the second and third merge heights to yield two cohesive groups where group diameter is bounded by the merge height and inter-group distance is large.

21
New cards

[Q4 - Part 1] Epsilon-Neighborhood Determination Rule

For each point, include itself plus every other point whose distance is at most epsilon, inclusive.

22
New cards

[Q4 - Part 2] Core Point Definition

A point that has at least MinPts points, including itself, within its epsilon-neighborhood.

23
New cards

[Q4 - Part 2] Border Point Definition

A point that has fewer than MinPts in its neighborhood but lies within epsilon of at least one core point.

24
New cards

[Q4 - Part 2] Noise Point Definition

A point that is neither a core point nor a border point.

25
New cards

[Q4 - Part 2] Classifying All Six Points Procedure

Count each neighborhood size, mark cores where size is at least MinPts, check if non-core points are within epsilon of a core, and label remaining as noise.

26
New cards

[Q4 - Part 3] Finding Clusters and Noise Procedure

Grow a cluster from a core point by connecting all density-reachable points, count resulting clusters, and label anything unassigned as noise.

27
New cards

[Q4 - Part 3] DBSCAN Dataset Preference Concept

DBSCAN is preferable for non-convex datasets like concentric rings or heavy noise because K-Means assumes spherical clusters and distorts centroids with outliers.

28
New cards

[Q4 - Part 3] Density-Reachability Concept

A point is density-reachable from a core point if there is a chain of core points connecting them within epsilon.

29
New cards

[Q4 - Part 3] Parameter Epsilon and MinPts Effects

Epsilon defines neighborhood radius and MinPts sets density thresholds, together controlling cluster granularity and noise identification.

30
New cards

[Q4 - Part 3] Noise Isolation in DBSCAN

DBSCAN explicitly isolates outliers as noise rather than forcing them into clusters, preserving cluster boundary integrity.

31
New cards

[Q5 - Part 1] Support Definition and Formula

Support = P(A union B) = count(A and B)/N, representing the proportion of transactions containing both items.

32
New cards

[Q5 - Part 1] Confidence Definition and Formula

Confidence = P(B|A) = support(A union B) / support(A), measuring rule reliability.

33
New cards

[Q5 - Part 1] Lift Definition and Formula

Lift = confidence / support(B) = P(A union B) / (P(A)P(B)), measuring observed joint support relative to independence.

34
New cards

[Q5 - Part 1] Lift Greater Than 1 Interpretation

Lift greater than 1 suggests a positive association where items occur together more often than expected by chance.

35
New cards

[Q5 - Part 2] Combinatorial Candidate Generation

A reason Apriori is expensive: d items yield up to 2^d minus 1 possible itemsets, creating massive candidate sets.

36
New cards

[Q5 - Part 2] Repeated Full-Database Scans

A reason Apriori is expensive: it scans the entire transaction set at every itemset length k to count candidate support.

37
New cards

[Q5 - Part 2] Hash-Based Pruning and Effort Reduction

Techniques like hash-based pruning, transaction reduction, or FP-Growth compress search effort or transaction sets to bypass candidate generation.

38
New cards

[Q5 - Part 2] Healthcare Application of Association Rules

Finding co-occurring symptoms, diagnoses, or adverse drug interactions in electronic health records.

39
New cards

[Q5 - Part 2] Cybersecurity Application of Association Rules

Finding co-occurring intrusion alert patterns or frequently co-visited web pages.

40
New cards

[Q5 - Part 3] Finding Frequent 1-Itemsets Method

Count each item across all transactions and prune those below the minimum support count threshold.

41
New cards

[Q5 - Part 3] Finding Frequent 2-Itemsets Method

Build candidate pairs only from frequent 1-itemsets, count occurrences across transactions, and prune below minimum support.

42
New cards

[Q5 - Part 3] Finding Frequent 3-Itemsets Method

Generate candidates, check that all subsets are frequent per the Apriori property, count supports, and write none if nothing qualifies.

43
New cards

[Q5 - Part 3] Listing Rules and Computing Confidence

List every rule with nonempty disjoint antecedent and consequent for each frequent itemset of size at least 2, and compute confidence.

44
New cards

[Q5 - Part 3] Computing Lift Method

Divide the rule's union support fraction by the product of individual support fractions for each rule meeting the confidence threshold.

45
New cards

[Q5 - Part 3] Lift Interpretation Below vs Above 1

Lift below 1 means items co-occur less often than chance due to high individual frequency, while lift above 1 indicates a genuine positive association.

46
New cards

[Q6 - Part 1] F1 Score Metric Definition

Measures the harmonic mean of precision and recall, balancing false positives and false negatives at a chosen threshold.

47
New cards

[Q6 - Part 1] Log-Loss Metric Definition

Measures the penalty for wrong probabilistic predictions, evaluating calibration where lower values are better.

48
New cards

[Q6 - Part 1] AUC Metric Definition

Measures the model's ability to rank positive instances higher than negatives across all possible classification thresholds.

49
New cards

[Q6 - Part 1] Random Forest vs Gradient Boosting Trade-Offs

Random Forest often yields strong F1 at default thresholds, while Gradient Boosting achieves superior probability calibration and ranking AUC.

50
New cards

[Q6 - Part 1] Justified Model Selection Procedure

Select Gradient Boosting for best calibration and discrimination with near-top F1, or Random Forest if F1 at the operating threshold is top priority.

51
New cards

[Q6 - Part 2] Stratified 5-Fold Cross-Validation Procedure

Partitions data into 5 folds preserving class distributions, trains on 4 folds and validates on 1, repeating five times so every observation is tested once.

52
New cards

[Q6 - Part 2] When Stratification Matters

Stratification matters for small or class-imbalanced datasets because it preserves the overall class distribution in every fold.

53
New cards

[Q6 - Part 2] Obtaining Final Cross-Validation Estimate

The final performance estimate is calculated as the arithmetic mean of the evaluation metric across all 5 validation folds.

54
New cards

[Q6 - Part 3] Usefulness of Identical Cross-Validation Folds

They create a paired comparison that removes variance from random splits, reflecting true model behavior differences.

55
New cards

[Q6 - Part 3] Testing Statistical Difference Between Models

To prove model B is better than A, mean differences alone are insufficient; you must analyze fold-by-fold accuracy differences.

56
New cards

[Q6 - Part 3] Statistical Tests for Model Comparison

Apply a paired t-test or Wilcoxon signed-rank test on fold-by-fold accuracy differences to establish statistical significance.

57
New cards

[Q6 - Part 3] Why Accuracy Is Misleading with Imbalance

When 3 percent of cases are positive, a trivial classifier predicting all negative gets 97 percent accuracy while catching 0 percent of positives.

58
New cards

[Q6 - Part 3] Informative Metrics for Rare Positives

PR-AUC or F1 are more informative because they evaluate precision and recall on the rare positive class without being inflated by true negatives.

59
New cards

[Q7 - Part 1] Blank 1 KMeans Initialization Code

km = KMeans(n_clusters=4, n_init=5, random_state=7) for fitting K-Means with 4 clusters, 5 initializations, and random state 7.

60
New cards

[Q7 - Part 1] Blank 2 Fit Predict Code

pred = km.fit_predict(X) to fit the model and return cluster label predictions for feature matrix X.

61
New cards

[Q7 - Part 1] Blank 3 Cluster Centers Code

print("Centroids:", km.cluster_centers_) to output the final coordinates of the cluster centroids.

62
New cards

[Q7 - Part 1] Blank 4 Silhouette Score Code

sil = silhouette_score(X, pred) to compute the internal validation metric based on cluster cohesion and separation.

63
New cards

[Q7 - Part 1] Blank 5 Adjusted Rand Score Code

ari = adjusted_rand_score(y, pred) to compute the external validation metric comparing predictions against true labels y.

64
New cards

[Q7 - Part 1] Blank 6 SSE Range Loop Code

for k in range(2, 8) to iterate SSE calculation for K values from 2 through 7 inclusive, accounting for exclusive upper bounds.

65
New cards

[Q7 - Part 1] Blank 7 Model Inertia Code

sse.append(model.inertia_) to store the sum of squared distances of samples to their closest cluster center.

66
New cards

[Q7 - Part 1] Blank 8 DBSCAN Initialization Code

db = DBSCAN(eps=0.8, min_samples=4) to initialize DBSCAN with epsilon 0.8 and minimum samples 4.

67
New cards

[Q7 - Part 1] Blank 9 Noise Count Code

noise_count = (db_labels == -1).sum() to count noise points since DBSCAN designates noise labels as -1.

68
New cards

[Q7 - Part 1] Blank 10 Cluster Count Code

cluster_count = len(set(db_labels)) - (1 if -1 in db_labels else 0) to exclude the noise label from the total cluster count.