MACHINE LEARNING

106403
Back to MACHINE LEARNING

Unit 4: Advanced Topics & Clustering

  1. Q1i. Type I error in hypothesis testing is (i) Accepting null when false (ii) Rejecting null when true (iii) Rejecting alternative when false (iv) Accepting alternative when true20252m

    Unit 4: Advanced Topics & Clustering

    Type I error in hypothesis testing is
    (i) Accepting null when false
    (ii) Rejecting null when true
    (iii) Rejecting alternative when false
    (iv) Accepting alternative when true

    View this question on its own page →
    Worked Solution

    Answer: (ii) Rejecting null when true

    Explanation — Hypothesis Testing Errors:

    Let H0H_0 = null hypothesis.

    • Type I Error (α\alpha): False Positive — reject H0H_0 when H0H_0 is actually true. P(Type I)=αP(\text{Type I}) = \alpha (significance level, e.g., 0.05). Example: Convicting an innocent person.
    • Type II Error (β\beta): False Negative — accept / fail to reject H0H_0 when H1H_1 is true (i.e., H0H_0 false). P(Type II)=βP(\text{Type II}) = \beta, Power =1−β=1-\beta. Example: Acquitting a guilty person.
    • (i) Accepting null when false → Type II
    • (ii) Rejecting null when true → Type I ✓
    • Confusion matrix mapping: Type I = FP, Type II = FN.

    Hence (ii) correct.

  2. Q1j. In Bagging, multiple models are trained on (i) The same dataset (ii) Only test data (iii) Random subsets of the training data (iv) Feature-reduced data only20252m

    Unit 4: Advanced Topics & Clustering

    In Bagging, multiple models are trained on
    (i) The same dataset
    (ii) Only test data
    (iii) Random subsets of the training data
    (iv) Feature-reduced data only

    View this question on its own page →
    Worked Solution

    Answer: (iii) Random subsets of the training data

    Explanation — Bagging (Bootstrap Aggregating):

    • Given training set DD of size nn, Bagging creates MM bootstrap samples DmD_m: each by sampling nn points with replacement → random subset (≈63.2% unique per bag, rest out-of-bag).
    • Train one base learner fmf_m on each DmD_m (e.g., decision trees in Random Forest).
    • Aggregate: classification by majority vote, regression by averaging: f^bag(x)=1M∑fm(x)\hat{f}_{bag}(x)=\frac1M\sum f_m(x).
    • Purpose: reduces variance, avoids overfitting, parallelizable.

    Contrast:

    • (i) same dataset — no diversity, defeats ensemble purpose
    • (ii) only test data — would be leakage, never train on test
    • (iv) feature-reduced only — that is feature bagging / Random Subspace part of Random Forest (both row + column sampling), but primary definition is row bootstrap.

    So (iii) is core.

  3. Q6a. Why is clustering important in machine learning? Show the steps of the k-means algorithm by taking a suitable example. Give the time complexity analysis of k-means.20257m

    Unit 4: Advanced Topics & Clustering

    Why is clustering important in machine learning? Show the steps of the k-means algorithm by taking a suitable example. Give the time complexity analysis of k-means.

    View this question on its own page →
    Worked Solution

    Why Clustering Important:
    Unsupervised, discovers hidden structure without labels. Uses: customer segmentation, gene grouping, image segmentation, anomaly detection, document clustering, feature engineering, data compression.

    K-means Algorithm Steps:

    Input: Data X={xi}i=1nX=\{x_i\}_{i=1}^n, kk, distance (Euclidean)
    Goal: minimize J=∑j=1k∑xi∈Cj∣∣xi−μj∣∣2J=\sum_{j=1}^k\sum_{x_i\in C_j}||x_i-\mu_j||^2

    1. Initialize: Choose kk centroids μj\mu_j randomly (k-means++ better).
    2. Assignment: Assign each xix_i to nearest centroid: Cj={xi:∣∣xi−μj∣∣≤∣∣xi−μl∣∣∀l}C_j=\{x_i: ||x_i-\mu_j|| \le ||x_i-\mu_l|| \forall l\}
    3. Update: Recompute μj=1∣Cj∣∑xi∈Cjxi\mu_j = \frac1{|C_j|}\sum_{x_i\in C_j} x_i
    4. Repeat 2-3 until centroids stop moving or JJ change < threshold (convergence to local optimum).

    Suitable Example:
    Data points: A(1,1), B(1.5,2), C(3,4), D(5,7), D(3.5,5), E(4.5,5), k=2k=2
    Init μ1=(1,1)\mu1=(1,1), μ2=(5,7)\mu2=(5,7)
    Iter1 assignments: cluster1 {A,B}, cluster2 {C,D}... recompute etc. After few iterations converges to two clusters.

    Time Complexity Analysis:
    Per iteration: O(n⋅k⋅d)O(n \cdot k \cdot d) distance computations (nn points, kk centroids, dd dims). For ii iterations: O(nkdi)O(n k d i). Space O((n+k)d)O((n+k)d). If k,dk,d constants, O(ni)O(n i) linear in nn. Compared to hierarchical O(n2)O(n^2). Elkan/Hamerly accelerations reduce but worst still O(nkdi)O(n k d i). Typically fast, converges quickly (10-100 iterations). Mention Lloyd's algorithm.

    Limitations: need pre-specify kk (elbow/silhouette), sensitive to init & outliers, assumes spherical clusters, Euclidean biased.

  4. Q6b. Compare bagging, AdaBoost, and gradient boosting. Discuss how each method reduces bias and variance and improves model performance.20257m

    Unit 4: Advanced Topics & Clustering

    Compare bagging, AdaBoost, and gradient boosting. Discuss how each method reduces bias and variance and improves model performance.

    View this question on its own page →
    Worked Solution

    Bagging vs AdaBoost vs Gradient Boosting:

    Bagging (Bootstrap Aggregating):

    • Parallel, bootstrap samples, full trees, reduces variance by averaging (Random Forest). Each model independent, weight equal. Robust to overfit, handles noisy data well. Example: M=100M=100 trees vote.

    AdaBoost (Adaptive Boosting — Freund & Schapire):

    • Sequential, adaptively reweights samples: increase weight for misclassified, decrease for correct. Weak learners typically stumps (depth=1depth=1). Final: F(x)=∑αtht(x)F(x)=\sum \alpha_t h_t(x), αt=12ln⁡((1−ϵt)/ϵt)\alpha_t=\frac12\ln((1-\epsilon_t)/\epsilon_t). Minimizes exponential loss ∑exp⁡(−yF(x))\sum \exp(-yF(x)).
    • Reduces bias (and some variance), very effective but sensitive to noise/outliers (weights blow up).

    Gradient Boosting (Friedman — GBM, XGBoost):

    • Sequential, fits new learner to residual / negative gradient of loss: ri(m)=−∂L(yi,Fm−1(xi))/∂Fm−1r_i^{(m)} = -\partial L(y_i,F_{m-1}(x_i))/\partial F_{m-1}. For squared loss r=y−Fr=y-F, for logistic gradient. Update $F_m=F_{m-1}+
      u \gamma_m h_m(x)( (
      u$ shrinkage).
    • Reduces bias, flexible (any differentiable loss), often strongest accuracy, needs careful tuning ( MM, learning rate, depth, regularization) to avoid overfit. XGBoost adds second-order Taylor, leaf weight regularization Ω=γT+12λ∣∣w∣∣2\Omega=\gamma T+\frac12\lambda||w||^2.

    Bias-Variance:

    • Bagging — primarily variance reduction (averaging decorrelated trees); slight bias increase if bootstrap.
    • Boosting — primarily bias reduction (sequentially correcting errors); variance can increase if too many iterations, controlled by shrinkage/early stopping.

    Choosing: Noisy, limited tuning time → Bagging/RF. Max accuracy, structured data → Gradient Boosting/XGBoost/LightGBM. Very weak stumps + exponential loss → AdaBoost (now largely superseded by GBM).

  5. Q9b. Write short note on: Hierarchical Clustering20257m

    Unit 4: Advanced Topics & Clustering

    Write short note on: Hierarchical Clustering

    View this question on its own page →
    Worked Solution

    Hierarchical Clustering:

    Unsupervised method building hierarchy / dendrogram of clusters — tree where leaves = points, internal nodes = merges/splits at certain distance.

    Two approaches:

    1. Agglomerative (Bottom-Up) — most common:

      • Start each point as cluster.
      • Repeat: find two closest clusters via linkage, merge, update distances.
      • Stop at k=1k=1 or desired kk (cut dendrogram).
      • Linkages:
        • Single linkage: d(Ci,Cj)=min⁡x∈Ci,y∈Cjd(x,y)d(C_i,C_j)=\min_{x\in C_i,y\in C_j} d(x,y) — produces elongated chains, sensitive to noise
        • Complete: max⁡\max distance — compact spherical clusters
        • Average: mean distance
        • Ward: minimizes increase in within-cluster SSE Δ=SSEmerged−SSEi−SSEj\Delta = SSE_{merged}-SSE_{i}-SSE_{j} — often best, prefers equal-sized.
      • Complexity O(n3)O(n^3) naive, O(n2log⁡n)O(n^2\log n) with heap, O(n2)O(n^2) memory.
    2. Divisive (Top-Down):

      • Start one cluster, recursively split (e.g., via K-means), rarer due to exponential.

    Dendrogram: Height = distance at merge; cut at height hh gives clustering. Can inspect for natural kk.

    Advantages: No preset kk needed (choose after), shows structure at multiple resolutions, deterministic, visualization.

    Disadvantages: Greedy (once merged cannot undo), sensitive to outliers/noise (single linkage), O(n2)O(n^2) memory limits large data, difficult to handle large nn (>10k).

    Example: Data points (1,2),(2,2),(8,8): single linkage merges first two at dist 1, then merges with (8,8) at ~8.5 distance dendrogram.

    Use: Gene expression phylogeny, document taxonomy, small-medium datasets where hierarchy insightful. Often combined with K-means for scale.