ML Handbook
← Open Study Guides Hub
Cheatsheet Sections
ML Master Cheatsheet
← Hub
Targets Regression Classification Bayes & KNN Trees PCA / K-Means Comparison

Strategic Score Target (60/40 University Rule)

Total Score = Internal Assessment (60%) + [Semester Exam Score × 0.40]

Internal Score
51.60 / 60
86.0% internal carryover.
Min Sem Mark for Grade A
49 / 100
(71.0 - 51.60) / 0.40 = 48.5.
Safe Target (+7 Buffer)
56 / 100
Final total = 74.00 (Grade A).
Target for Grade A+ / S
74 / 100
Final total = 81.00 ≥ 81.0.

02. Linear Regression & Optimization Foundations

Ordinary Least Squares (OLS) Closed-Form

$$\hat{\beta}_1 = \frac{\sum_{i=1}^n (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^n (X_i - \bar{X})^2} = \frac{\operatorname{Cov}(X, Y)}{\operatorname{Var}(X)}, \qquad \hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}$$ $$\text{Matrix Normal Equation: } \hat{\boldsymbol{\beta}} = \left(\mathbf{X}^T \mathbf{X}\right)^{-1} \mathbf{X}^T \mathbf{y}$$

Regularization Penalties

Ridge Regression ($L_2$): $\min_{\mathbf{w}} \frac{1}{2n}\|\mathbf{y} - \mathbf{X}\mathbf{w}\|_2^2 + \lambda \|\mathbf{w}\|_2^2 \implies \hat{\mathbf{w}} = (\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1}\mathbf{X}^T\mathbf{y}$

Lasso Regression ($L_1$): $\min_{\mathbf{w}} \frac{1}{2n}\|\mathbf{y} - \mathbf{X}\mathbf{w}\|_2^2 + \lambda \|\mathbf{w}\|_1$ (Produces exact sparse zeros for feature selection)

Regression Metrics

$$\text{MSE} = \frac{1}{n}\sum (Y_i - \hat{Y}_i)^2, \quad \text{RMSE} = \sqrt{\text{MSE}}, \quad \text{MAE} = \frac{1}{n}\sum |Y_i - \hat{Y}_i|$$ $$R^2 = 1 - \frac{\sum (Y_i - \hat{Y}_i)^2}{\sum (Y_i - \bar{Y})^2}, \quad \text{Adjusted } R^2 = 1 - \left[\frac{(1 - R^2)(n - 1)}{n - p - 1}\right]$$

03. Logistic Regression & Classification Metrics

The Sigmoid Mapping & Multi-Class Softmax

$$\text{Odds} = \frac{p}{1 - p}, \quad \ln\left(\frac{p}{1 - p}\right) = \mathbf{w}^T\mathbf{x} + b \implies p = \sigma(z) = \frac{1}{1 + e^{-z}}$$ $$\text{Softmax Multi-Class: } P(Y = k \mid \mathbf{x}) = \frac{e^{\mathbf{w}_k^T\mathbf{x} + b_k}}{\sum_{j=1}^K e^{\mathbf{w}_j^T\mathbf{x} + b_j}}$$

Classification Metrics & Rare Events

$$\text{Accuracy} = \frac{TP + TN}{N}, \quad \text{Precision} = \frac{TP}{TP + FP}, \quad \text{Recall} = \frac{TP}{TP + FN}$$ $$F_1\text{-Score} = \frac{2 \cdot \text{Prec} \cdot \text{Rec}}{\text{Prec} + \text{Rec}}, \quad F_2\text{-Score} = \frac{5 \cdot \text{Prec} \cdot \text{Rec}}{4\text{Prec} + \text{Rec}}$$

The Accuracy Paradox: On rare-event datasets (e.g. 0.5% fraud), a null model predicting 100% negative achieves 99.5% accuracy but 0% recall. PR-AUC and $F_2$-score are mandatory over ROC-AUC (which is inflated by massive $TN$).

04. Naïve Bayes & K-Nearest Neighbors (KNN)

Naïve Bayes Formulation

$$P(C = c \mid \mathbf{x}) = \frac{P(C = c) \prod_{j=1}^d P(x_j \mid C = c)}{P(\mathbf{x})}$$ $$\text{Laplace Add-1 Smoothing: } P(x_j \mid C = c) = \frac{\operatorname{Count}(x_j \text{ and } c) + 1}{\operatorname{Count}(c) + K}$$

K-Nearest Neighbors Geometry

$$d_{\text{Euclidean}}(\mathbf{q}, \mathbf{x}) = \sqrt{\sum (q_j - x_j)^2}, \qquad d_{\text{Manhattan}}(\mathbf{q}, \mathbf{x}) = \sum |q_j - x_j|$$

$K$ Tradeoff: $K=1 \implies$ High Variance (Overfitting, noisy boundaries). $K \to N \implies$ High Bias (Underfitting, majority class collapse). Optimal: $K \approx \sqrt{N}$ (odd number).

05. Decision Trees & Ensemble Methods

Splitting Criteria (ID3 vs CART)

$$H(S) = -\sum p_i \log_2(p_i), \qquad \operatorname{Gain}(S, A) = H(S) - \sum \frac{|S_v|}{|S|}H(S_v)$$ $$\operatorname{Gini}(S) = 1 - \sum p_i^2, \qquad \operatorname{Gini}_{\text{split}}(S, A) = \sum \frac{|S_v|}{|S|}\operatorname{Gini}(S_v)$$

Random Forest Variance Reduction Theorem

$$\operatorname{Var}\left(\hat{f}_{\text{RF}}\right) = \rho \sigma^2 + \frac{1 - \rho}{B}\sigma^2$$

As trees $B \to \infty$, variance approaches $\rho \sigma^2$. Random feature subsampling ($m \approx \sqrt{p}$) decorrelates trees ($\rho \to 0$), driving total variance to zero.

AdaBoost Reweighting

$$\epsilon_t = \sum_{\text{misclassified}} w_t(i), \quad \alpha_t = \frac{1}{2}\ln\left(\frac{1 - \epsilon_t}{\epsilon_t}\right), \quad w_{t+1}(i) = \frac{w_t(i) e^{-\alpha_t y_i h_t(\mathbf{x}_i)}}{Z_t}$$

06. Clustering (K-Means) & Dimensionality Reduction (PCA)

K-Means Objective & Silhouette Score

$$\arg\min_{\mathcal{C}} \operatorname{WCSS} = \sum_{k=1}^K \sum_{\mathbf{x} \in C_k} \|\mathbf{x} - \boldsymbol{\mu}_k\|^2, \qquad s(i) = \frac{b(i) - a(i)}{\max(a(i), b(i))}$$

PCA via Dual SVD ($p \gg n$)

$$\tilde{\mathbf{X}} = \mathbf{U} \mathbf{S} \mathbf{V}^T \in \mathbb{R}^{n \times p}, \qquad \lambda_j = \frac{s_j^2}{n - 1}$$

Computes in $O(n^2 p)$ time instead of $O(p^3)$ covariance eigendecomposition ($2500\times$ faster). Translate latent PCs to biomarkers via factor loadings $\mathbf{V}_k$ and Differential Expression Analysis (FDR $q \le 0.05$).

07. Master Algorithm Comparison Matrix

Algorithm Learning Type Training Complexity Inference Complexity Primary Hyperparameter Handling Outliers
Linear Regression (OLS) Parametric $O(d^2 n + d^3)$ $O(d)$ None (Closed-form) Sensitive (Squared errors)
Ridge / Lasso Parametric Regularized $O(d^3)$ or Iterative $O(d)$ $\lambda$ (Penalty strength) More robust than OLS
Logistic Regression Parametric Probabilistic $O(\text{epochs} \cdot n \cdot d)$ $O(d)$ $\lambda$ / Regularization $C$ Robust with sigmoid
K-Nearest Neighbors (KNN) Non-Parametric Lazy $O(1)$ $O(n \cdot d)$ $K$ (Number of neighbors) Sensitive when $K=1$
Naïve Bayes Generative Probabilistic $O(n \cdot d)$ $O(d)$ $\alpha$ (Laplace smoothing) Highly robust
Decision Trees (CART/ID3) Non-Parametric Tree $O(n \cdot d \cdot \log n)$ $O(\text{depth}) \le O(\log n)$ `max_depth`, `min_samples_split` Robust (Monotonic splits)
Random Forest Bagged Ensemble $O(B \cdot n \cdot d \log n)$ $O(B \cdot \log n)$ $B$ (trees), $m$ (features) Highly robust
AdaBoost Sequential Boosting $O(T \cdot n \cdot d)$ $O(T)$ $T$ (Iterations), Learning Rate Sensitive to noisy labels
K-Means Clustering Unsupervised Partitional $O(I \cdot K \cdot n \cdot d)$ $O(K \cdot d)$ $K$ (Clusters) Sensitive to outliers
PCA (Dual SVD) Unsupervised Projection $O(n^2 p)$ for $p \gg n$ $O(k \cdot p)$ $k$ (Retained variance $\ge 85\%$) Sensitive (variance maximized)