# PCA Eigen-Directions, K-Means/DBSCAN Clustering & Neural Net Backpropagation
Exam: GATE Data Science & Artificial Intelligence (DA) (GATE DA)
Subject: Machine Learning & Deep Learning
Canonical URL: https://gateandnet.com/exams/gate-da/machine-learning-and-ai/pca-clustering-and-backpropagation

> Covariance matrix eigenvectors & proportion of variance explained in PCA, K-Means Lloyd objective vs DBSCAN density reachability, MLP Softmax Cross-Entropy gradient, and CNN output shapes.

## 1. Principal Component Analysis (PCA)

Center data $X_c = X - \mathbf{1}\mu^T$. Maximizing projected variance $u_1^T \Sigma u_1$ subject to $\|u_1\|_2^2 = 1$ via Lagrange multiplier $L(u_1, \lambda) = u_1^T \Sigma u_1 - \lambda(u_1^T u_1 - 1)$ gives:

$$
\nabla_{u_1} L = 2\Sigma u_1 - 2\lambda u_1 = 0 \implies \Sigma u_1 = \lambda u_1
$$

1. The $k$-th principal component direction $u_k$ is the unit **eigenvector** corresponding to the $k$-th largest eigenvalue $\lambda_k$ of $\Sigma$ (equivalently, right singular vector $v_k$ of $X_c = U S V^T$ with $\lambda_k = s_k^2 / n$).
2. Principal components are mutually **orthogonal** ($u_i^T u_j = 0$ for $i \neq j$) and uncorrelated in projected space.
3. Minimizing **mean squared reconstruction error** $\frac{1}{n}\|X_c - X_c U_k U_k^T\|_F^2$ yields the **exact same** top-$k$ eigenvectors (discarded error $= \sum_{j=k+1}^d \lambda_j$)!

## 2. Clustering: K-Means vs Hierarchical vs DBSCAN

| Algorithm | Cluster Shape | Requires $K$ Upfront? | Handles Noise / Outliers? | Time Complexity |
| :--- | :--- | :---: | :---: | :---: |
| **K-Means (Lloyd’s)** | Convex / Spherical (Voronoi) | ✅ Yes | ❌ Sensitive to outliers | $\mathcal{O}(t \cdot K \cdot n \cdot d)$ |
| **Agglomerative Hierarchical** | Arbitrary (Single-Link) / Compact (Complete) | ❌ Dendrogram cut | ⚠️ Single-link chains on noise | $\mathcal{O}(n^2 \log n)$ |
| **DBSCAN ($\epsilon, \text{MinPts}$)** | Arbitrary non-convex shapes | ❌ **No** | ✅ Labels sparse points as Noise | $\mathcal{O}(n \log n)$ (spatial index) |

## 3. Neural Networks, Activations & Backpropagation

- **Sigmoid $\sigma(z) = \frac{1}{1 + e^{-z}}$:** Derivative $\sigma'(z) = \sigma(z)(1 - \sigma(z)) \le \mathbf{0.25}$ (at $z=0$). Multiplying $\le 0.25$ across $L$ layers causes **vanishing gradients**!
- **ReLU $\max(0, z)$:** Derivative is $1$ for $z > 0$ (no saturation for positive activations!), $0$ for $z < 0$ (*Dying ReLU* if learning rate is too high $\to$ fixed by Leaky ReLU / GELU).
- **Softmax + Cross-Entropy Clean Gradient:** For logits $z \in \mathbb{R}^K$, probabilities $\hat{y}_c = \frac{e^{z_c}}{\sum_j e^{z_j}}$, and one-hot target $y$:

$$
\frac{\partial \mathcal{L}_{\text{CE}}}{\partial z} = \hat{y} - y
$$

## Solved Practice Questions & PYQs

### [GATE DA ML | MCQ]
The sample covariance matrix $\Sigma$ of a $4$-dimensional centered dataset has eigenvalues $\{12, 5, 2, 1\}$. What percentage of total variance is preserved by projecting onto the **first two Principal Components**?
**Correct Answer:** C
**Solution:** Total variance $= \operatorname{tr}(\Sigma) = 12 + 5 + 2 + 1 = 20$. Top-2 eigenvalues explain $\frac{12 + 5}{20} = \frac{17}{20} = \mathbf{85\%}$ of the variance.

### [GATE DA Deep Learning | MCQ]
A 2D Convolutional layer takes an input volume of size $32 \times 32 \times 3$ and applies $16$ filters of spatial size $5 \times 5$ with **stride $S = 1$**, **padding $P = 2$**, and one bias parameter per filter. What is the **output shape** and **total trainable parameter count**?
**Correct Answer:** A
**Solution:** - Spatial size $O = \lfloor \frac{32 - 5 + 2(2)}{1} \rfloor + 1 = 32$ (*"same"* padding) $\implies \mathbf{32 \times 32 \times 16}$.
- Trainable parameters $= (5 \times 5 \times 3 + 1) \times 16 = 76 \times 16 = \mathbf{1,216}$.

### [GATE DA Clustering | MCQ]
Which clustering algorithm can discover **non-convex concentric ring clusters** AND explicitly identify isolated **noise / outlier** points without pre-specifying the number of clusters $K$?
**Correct Answer:** B
**Solution:** **DBSCAN** groups density-reachable core/border points using $(\epsilon, \text{MinPts})$, effortlessly tracing arbitrary non-convex shapes (like concentric moons/rings) while labeling low-density points as **Noise** without needing $K$.
