Skip to content
GATEiit

GATE DA Machine Learning formula sheet

Core formulas for GATE DA machine learning: regression, classification (logistic, k-NN, naive Bayes, LDA, SVM, decision trees), bias-variance, cross-validation, neural networks, clustering and PCA.

55 formulas · updated 2026-11-14 · reviewed 2026-11-14 · Spotted an error? Tell us

Regression: simple, multiple and ridge

  • Regression vs classification loss

    MSE=1n∑i=1n(yi−y^i)2,0-1 loss=1n∑i=1n1[yi≠y^i]

    Regression predicts a real-valued target; classification predicts a discrete label.

  • Simple linear regression (OLS)

    β^1=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2=r sysx,β^0=yˉ−β^1xˉ

    The fitted line always passes through (xˉ,yˉ).

  • Residual properties

    ∑iei=0,∑ixiei=0,ei=yi−y^i

    Hold for least squares with an intercept term; in matrix form X⊤e=0.

  • Coefficient of determination

    R2=1−SSESST=1−∑(yi−y^i)2∑(yi−yˉ)2

    For simple linear regression with intercept, R2=r2 (squared correlation).

  • Multiple regression (normal equations)

    β^=(X⊤X)−1X⊤y

    Minimizes ∥y−Xβ∥2; needs X⊤X invertible (full column rank). Add a column of 1s for the intercept.

  • Hat matrix

    H=X(X⊤X)−1X⊤,y^=Hy,H2=H=H⊤,tr⁡(H)=p

    p = number of columns of X (including the intercept column). Diagonal entries hii are leverages.

  • Ridge regression

    β^ridge=arg⁡min⁡β∥y−Xβ∥2+λ∥β∥2=(X⊤X+λI)−1X⊤y

    For λ>0 the matrix is always invertible. Shrinks coefficients towards 0 but not exactly to 0; intercept usually not penalized.

  • Ridge, one feature, no intercept

    β^=∑xiyi∑xi2+λ

    λ=0 gives OLS; λ→∞ gives β^→0. Larger λ: higher bias, lower variance.

Logistic regression

  • Sigmoid function

    σ(z)=11+e−z,σ′(z)=σ(z)(1−σ(z)),σ(−z)=1−σ(z)

    σ(0)=0.5; maximum slope σ′(0)=0.25.

  • Model and log-odds

    P(y=1∣x)=σ(w⊤x+b),ln⁡p1−p=w⊤x+b

    Log-odds are linear in x; increasing xj by 1 multiplies the odds by ewj.

  • Decision boundary

    w⊤x+b=0

    With threshold 0.5 the boundary is a hyperplane, so logistic regression is a linear classifier.

  • Cross-entropy loss and gradient

    L=−∑i[yiln⁡pi+(1−yi)ln⁡(1−pi)],∇wL=∑i(pi−yi) xi

    Here yi∈{0,1}, pi=σ(w⊤xi+b). Loss is convex but has no closed-form minimizer; use gradient methods.

  • Softmax (multi-class)

    P(y=k∣x)=ezk∑j=1Kezj,zk=wk⊤x+bk

    Probabilities sum to 1; adding the same constant to every zk does not change the output.

k-nearest neighbour and naive Bayes

  • Distance metrics

    dp(x,z)=(∑j∣xj−zj∣p)1/p

    p=1 Manhattan, p=2 Euclidean, p→∞ Chebyshev (max⁡j∣xj−zj∣). Scale features first.

  • k-NN prediction

    y^=mode⁡{yi:i∈Nk(x)} (class),y^=1k∑i∈Nk(x)yi (regression)

    Small k: low bias, high variance (1-NN has zero training error if no duplicate points with different labels). Large k: smoother, higher bias.

  • Bayes' theorem

    P(c∣x)=P(x∣c) P(c)∑c′P(x∣c′) P(c′)

    Posterior is proportional to likelihood times prior; denominator is the same for all classes.

  • Naive Bayes classifier

    c^=arg⁡max⁡c P(c)∏j=1dP(xj∣c)

    Assumes features are conditionally independent given the class. Use sums of logs to avoid underflow.

  • Laplace (add-one) smoothing

    P(xj=v∣c)=Nc,j,v+1Nc+Kj

    Nc = training examples of class c, Kj = number of possible values of feature j. Avoids zero probabilities wiping out the product.

  • Gaussian naive Bayes

    P(xj∣c)=12πσjc2exp⁡ ⁣(−(xj−μjc)22σjc2)

    For continuous features; μjc,σjc2 are the mean and variance of feature j within class c.

Linear discriminant analysis and SVM

  • LDA discriminant function

    δk(x)=x⊤Σ−1μk−12μk⊤Σ−1μk+ln⁡πk

    Assumes Gaussian classes with a common covariance Σ; predict arg⁡max⁡kδk. Boundaries are linear (unequal covariances give quadratic QDA).

  • 1-D LDA threshold

    x∗=μ1+μ22

    For two classes with equal variance and equal priors. Unequal priors shift the threshold towards the less likely class mean.

  • Fisher's linear discriminant

    J(w)=w⊤SBww⊤SWw,w∗∝SW−1(μ1−μ2)

    SB=(μ1−μ2)(μ1−μ2)⊤, SW=∑k∑x∈Ck(x−μk)(x−μk)⊤. With K classes, at most K−1 directions.

  • Distance to hyperplane

    d(x0)=∣w⊤x0+b∣∥w∥

    Signed distance drops the absolute value; sign tells the side of the hyperplane.

  • Hard-margin SVM

    min⁡w,b 12∥w∥2  s.t.  yi(w⊤xi+b)≥1,margin=2∥w∥

    Labels yi∈{−1,+1}; requires linearly separable data. Distance from boundary to nearest point is 1/∥w∥.

  • Soft-margin SVM

    min⁡ 12∥w∥2+C∑iξi  s.t.  yi(w⊤xi+b)≥1−ξi, ξi≥0

    Large C: fewer margin violations, narrower margin (risk of overfitting). Small C: wider margin, more violations.

  • Hinge loss

    ℓ(y,f(x))=max⁡(0, 1−y f(x))

    Zero only when the point is correctly classified with yf(x)≥1 (outside or on the margin).

  • SVM dual and support vectors

    w=∑iαiyixi,∑iαiyi=0,0≤αi≤C

    Only support vectors have αi>0; removing a non-support vector does not change the solution. Hard margin: C=∞.

  • Kernels

    K(x,z)=x⊤z,(x⊤z+c)d,exp⁡ ⁣(−γ∥x−z∥2)

    Linear, polynomial, RBF. A valid kernel must give a symmetric positive semidefinite Gram matrix (Mercer).

Decision trees

  • Entropy

    H(S)=−∑k=1Kpklog⁡2pk

    0 for a pure node; maximum log⁡2K for a uniform split (1 bit for a 50/50 binary node). Take 0log⁡0=0.

  • Information gain

    IG(S,A)=H(S)−∑v∈values(A)∣Sv∣∣S∣H(Sv)

    ID3 picks the attribute with the largest gain. IG is always ≥0.

  • Gini index

    G(S)=1−∑k=1Kpk2

    Used by CART; 0 for a pure node, maximum 1−1/K (0.5 for binary).

  • Misclassification error

    E(S)=1−max⁡kpk

    Less sensitive to node purity changes than entropy or Gini; mainly used for pruning.

  • Gain ratio

    GR(S,A)=IG(S,A)−∑v∣Sv∣∣S∣log⁡2∣Sv∣∣S∣

    C4.5 criterion; the denominator (split information) penalizes attributes with many values, which IG favours.

  • Regression tree

    y^leaf=1∣S∣∑i∈Syi,split minimizes ∑children∑i(yi−yˉchild)2

    Deep trees have low bias and high variance; limit depth or prune to reduce overfitting.

Bias-variance trade-off and cross-validation

  • Bias-variance decomposition

    E[(y−f^(x))2]=(E[f^(x)]−f(x))2+Var⁡(f^(x))+σ2

    For y=f(x)+ε, E[ε]=0, Var⁡(ε)=σ2; expectation over training sets and noise. σ2 is irreducible error.

  • Complexity trend

    complexity↑ ⇒ bias2↓,  variance↑

    Underfitting = high bias (high train and test error); overfitting = high variance (low train, high test error). Ridge λ↑ or k-NN k↑ lowers variance, raises bias.

  • k-fold cross-validation

    CV(k)=1k∑i=1kErri

    Split data into k folds; train on k−1 folds (about n(k−1)/k points), test on the held-out fold. k model fits; each point is validated exactly once.

  • Leave-one-out CV

    CV(n)=1n∑i=1n(yi−y^i(−i))2

    k-fold with k=n: n fits, each on n−1 points. Nearly unbiased but higher-variance estimate; no randomness in the splits.

  • LOOCV shortcut for least squares

    CV(n)=1n∑i=1n(yi−y^i1−hii)2

    Exact for ordinary least squares (linear regression) using one full fit; hii is the leverage from the hat matrix.

Multi-layer perceptron and feed-forward networks

  • Perceptron

    y^=sign⁡(w⊤x+b),if yi≠y^i: w←w+η yixi, b←b+η yi

    Labels ±1. Converges in finitely many updates if the data are linearly separable; a single perceptron cannot learn XOR.

  • Forward pass

    z(l)=W(l)a(l−1)+b(l),a(l)=g(z(l))

    a(0)=x. W(l) has shape nl×nl−1.

  • Parameter count

    #params=∑l=1L(nl−1+1) nl

    Weights nl−1nl plus nl biases per fully connected layer.

  • Activation functions

    ReLU⁡(z)=max⁡(0,z),tanh⁡′(z)=1−tanh⁡2(z),tanh⁡(z)=2σ(2z)−1

    ReLU derivative is 1 for z>0, 0 for z<0. Sigmoid/tanh saturate, causing vanishing gradients.

  • Linear layers collapse

    W2(W1x+b1)+b2=(W2W1)x+(W2b1+b2)

    Without non-linear activations, any depth of network is just a linear model.

  • Backpropagation

    δ(l)=(W(l+1)⊤δ(l+1))⊙g′(z(l)),∂L∂W(l)=δ(l)a(l−1)⊤,  ∂L∂b(l)=δ(l)

    δ(l)=∂L/∂z(l); start from the output layer δ(L)=∇a(L)L⊙g′(z(L)).

  • Softmax/sigmoid + cross-entropy gradient

    ∂L∂z(L)=y^−y

    Holds for softmax with categorical cross-entropy (one-hot y) and for sigmoid with binary cross-entropy.

  • Gradient descent update

    θ←θ−η ∇θL

    Batch uses all data, stochastic uses one example, mini-batch uses a subset per step.

Clustering and PCA

  • k-means objective

    J=∑k=1K∑xi∈Ck∥xi−μk∥2,μk=1∣Ck∣∑xi∈Ckxi

    Alternate: assign each point to nearest centroid, then recompute means. J never increases; converges to a local (not necessarily global) minimum that depends on initialization.

  • k-medoid

    mk=arg⁡min⁡m∈Ck∑xi∈Ckd(xi,m)

    The medoid is an actual data point; works with any dissimilarity and is more robust to outliers than k-means (e.g. PAM).

  • Hierarchical linkage criteria

    dsingle=min⁡a∈A,b∈Bd(a,b),dcomplete=max⁡a∈A,b∈Bd(a,b),davg=1∣A∣∣B∣∑a∈A∑b∈Bd(a,b)

    Single linkage tends to chain; complete linkage gives compact clusters. Agglomerative (bottom-up) does n−1 merges; divisive is top-down. Cut the dendrogram to get clusters.

  • PCA: covariance and eigenvectors

    S=1n∑i=1n(xi−xˉ)(xi−xˉ)⊤,Svj=λjvj

    Center the data first. Principal components are eigenvectors of S ordered by λ1≥λ2≥⋯; they are orthonormal. (1/(n−1) scaling gives the same directions.)

  • First principal component

    v1=arg⁡max⁡∥w∥=1w⊤Sw,max⁡=λ1

    Variance of the data projected on vj equals λj; projected scores on different PCs are uncorrelated.

  • Explained variance

    λk∑j=1dλj,∑j=1dλj=tr⁡(S)

    Total variance equals the sum of feature variances; keep the top m PCs that capture the desired fraction.

  • Projection and reconstruction

    z=Vm⊤(x−xˉ),x^=xˉ+Vmz,1n∑i∥xi−x^i∥2=∑j>mλj

    Vm holds the top m eigenvectors as columns. Average reconstruction error equals the sum of discarded eigenvalues (with the 1/n covariance).

  • PCA via SVD

    Xc=UΣV⊤,λj=σj2n

    Xc is the centered n×d data matrix; PCs are the columns of V (right singular vectors).

Where marks come fromTopic-wise PYQ analysis →Use the formulasPractise PYQs on this subject →For numerical answersGATE virtual calculator →