All Categories

Machine Learning & AI

Core algorithms behind machine learning and AI — models, activation functions, loss functions, optimizers, deep learning and reinforcement learning.

Machine Learning & AI formulas capture the core mathematics behind how modern models learn, predict, and improve, from linear regression and gradient descent to activation functions, loss functions, and similarity measures. This category is useful for students revising theory, exam preparation, and anyone applying AI in real projects, because these formulas explain how algorithms make decisions, train efficiently, and measure performance.

Linear Regression Model

Basic
y^=w⊤x+b\hat{y} = \mathbf{w}^\top \mathbf{x} + b

Predicts a continuous value as a weighted sum of input features plus a bias.

View details

Gradient Descent Update

Basic
θ:=θ−α ∇θJ(θ)\theta := \theta - \alpha\,\nabla_\theta J(\theta)

Iteratively moves parameters in the direction that most reduces the loss.

View details

ReLU Activation

Basic
f(x)=max⁡(0,x)f(x) = \max(0, x)

Rectified Linear Unit: outputs the input if positive, else zero.

View details

Leaky ReLU

Basic
f(x)=max⁡(αx,x)f(x) = \max(\alpha x, x)

A ReLU variant that lets a small gradient flow for negative inputs.

View details

Tanh Activation

Basic
tanh⁡(x)=ex−e−xex+e−x\tanh(x) = \dfrac{e^{x}-e^{-x}}{e^{x}+e^{-x}}

Squashes input to the range (-1, 1); zero-centred activation.

View details

Softmax

Basic
σ(z)i=ezi∑jezj\sigma(z)_i = \dfrac{e^{z_i}}{\sum_{j} e^{z_j}}

Turns a vector of scores into a probability distribution that sums to 1.

View details

Binary Cross-Entropy

Basic
L=−[ylog⁡y^+(1−y)log⁡(1−y^)]L = -\big[y\log\hat{y} + (1-y)\log(1-\hat{y})\big]

Loss for binary classification comparing predicted probability to the true label.

View details

Categorical Cross-Entropy

Basic
L=−∑iyilog⁡y^iL = -\sum_{i} y_i \log \hat{y}_i

Multi-class loss summing the log-probability of the correct class.

View details

Logistic Regression

Basic
y^=11+e−(w⊤x+b)\hat{y} = \dfrac{1}{1+e^{-(\mathbf{w}^\top \mathbf{x}+b)}}

Applies the sigmoid to a linear model to output a class probability.

View details

Euclidean Distance (KNN)

Basic
d(p,q)=∑i(pi−qi)2d(\mathbf{p},\mathbf{q}) = \sqrt{\sum_i (p_i-q_i)^2}

Straight-line distance between two points; the default metric for k-nearest neighbours.

View details

Cosine Similarity

Basic
cos⁡θ=a⋅b∥a∥ ∥b∥\cos\theta = \dfrac{\mathbf{a}\cdot\mathbf{b}}{\lVert\mathbf{a}\rVert\,\lVert\mathbf{b}\rVert}

Measures the angle between two vectors; 1 means identical direction.

View details

Entropy (Information)

Intermediate
H(S)=−∑ipilog⁡2piH(S) = -\sum_i p_i \log_2 p_i

Measures impurity/uncertainty of a set; used to split decision trees.

View details

Gini Impurity

Intermediate
G=1−∑ipi2G = 1 - \sum_i p_i^2

Probability of misclassifying a random sample; the default split metric in CART trees.

View details

Information Gain

Intermediate
IG=H(S)−∑k∣Sk∣∣S∣H(Sk)IG = H(S) - \sum_k \dfrac{|S_k|}{|S|}H(S_k)

Reduction in entropy achieved by splitting a node on a feature.

View details

Naive Bayes Posterior

Intermediate
P(y∣x)∝P(y)∏iP(xi∣y)P(y\mid \mathbf{x}) \propto P(y)\prod_i P(x_i\mid y)

Classifies by assuming features are conditionally independent given the class.

View details

L2 Regularization (Ridge)

Intermediate
J=MSE+λ∑jwj2J = \text{MSE} + \lambda\sum_j w_j^2

Adds a penalty on squared weights to reduce overfitting.

View details

L1 Regularization (Lasso)

Intermediate
J=MSE+λ∑j∣wj∣J = \text{MSE} + \lambda\sum_j |w_j|

Penalizes absolute weights, driving many to exactly zero for feature selection.

View details

Hinge Loss (SVM)

Intermediate
L=max⁡(0, 1−y y^)L = \max(0,\,1 - y\,\hat{y})

Loss for support vector machines; zero once a point is correctly classified with margin.

View details

SVM Margin

Intermediate
M=2∥w∥M = \dfrac{2}{\lVert \mathbf{w}\rVert}

Width of the separating margin an SVM maximizes between classes.

View details

Perceptron Update

Intermediate
w:=w+η (y−y^) x\mathbf{w} := \mathbf{w} + \eta\,(y-\hat{y})\,\mathbf{x}

The original learning rule that nudges weights when a prediction is wrong.

View details

SGD with Momentum

Intermediate
v:=βv+(1−β)∇J;    θ:=θ−αvv := \beta v + (1-\beta)\nabla J;\;\; \theta := \theta - \alpha v

Accelerates gradient descent by accumulating a velocity of past gradients.

View details

Adam Optimizer

Intermediate
θ:=θ−α m^tv^t+ϵ\theta := \theta - \alpha\,\dfrac{\hat{m}_t}{\sqrt{\hat{v}_t}+\epsilon}

Adaptive optimizer combining momentum and per-parameter learning rates.

View details

RMSProp

Intermediate
E[g2]t=γE[g2]t−1+(1−γ)gt2E[g^2]_t = \gamma E[g^2]_{t-1} + (1-\gamma)g_t^2

Scales the learning rate by a running average of recent squared gradients.

View details

Exponential LR Decay

Intermediate
αt=α0 e−kt\alpha_t = \alpha_0\, e^{-k t}

Gradually lowers the learning rate as training progresses.

View details

K-Means Objective (WCSS)

Intermediate
J=∑k=1K∑x∈Ck∥x−μk∥2J = \sum_{k=1}^{K}\sum_{\mathbf{x}\in C_k}\lVert \mathbf{x}-\mu_k\rVert^2

Clustering minimizes the total squared distance of points to their cluster centre.

View details

Batch Normalization

Advanced
x^=x−μBσB2+ϵ\hat{x} = \dfrac{x-\mu_B}{\sqrt{\sigma_B^2+\epsilon}}

Normalizes layer inputs across a mini-batch to speed and stabilize training.

View details

Dropout (Inverted)

Advanced
x~=x⊙m1−p\tilde{x} = \dfrac{x\odot m}{1-p}

Randomly zeroes activations during training to prevent co-adaptation.

View details

TF-IDF

Advanced
tfidf=tf⋅log⁡Ndf\text{tfidf} = tf \cdot \log\dfrac{N}{df}

Weights a word by its frequency in a document against its rarity across the corpus.

View details

PCA (Covariance)

Advanced
C=1nX⊤X,    Cv=λv\mathbf{C} = \tfrac{1}{n}\mathbf{X}^\top\mathbf{X},\;\; \mathbf{C}\mathbf{v}=\lambda\mathbf{v}

Finds directions of maximum variance via eigenvectors of the covariance matrix.

View details

Scaled Dot-Product Attention

Advanced
Attn(Q,K,V)=softmax ⁣(QK⊤dk)V\text{Attn}(Q,K,V)=\text{softmax}\!\left(\dfrac{QK^\top}{\sqrt{d_k}}\right)V

Lets each token weigh and aggregate information from all others — the heart of Transformers.

View details

Positional Encoding

Advanced
PE(pos,2i)=sin⁡ ⁣(pos100002i/d)PE_{(pos,2i)}=\sin\!\left(\dfrac{pos}{10000^{2i/d}}\right)

Injects word-order information into a Transformer that otherwise ignores position.

View details

Layer Normalization

Advanced
x^=x−μσ2+ϵ γ+β\hat{x}=\dfrac{x-\mu}{\sqrt{\sigma^2+\epsilon}}\,\gamma+\beta

Normalizes across features within a single sample; standard in Transformers.

View details

KL Divergence

Advanced
DKL(P∥Q)=∑iP(i)log⁡P(i)Q(i)D_{KL}(P\Vert Q)=\sum_i P(i)\log\dfrac{P(i)}{Q(i)}

Measures how one probability distribution differs from a reference distribution.

View details

Bellman Equation

Advanced
V(s)=max⁡a[R(s,a)+γ∑s′P(s′∣s,a)V(s′)]V(s)=\max_a\Big[R(s,a)+\gamma\sum_{s^{\prime}}P(s^{\prime}\mid s,a)V(s^{\prime})\Big]

Expresses the value of a state as the best immediate reward plus discounted future value.

View details

Q-Learning Update

Advanced
Q(s,a):=Q(s,a)+α[r+γmax⁡a′Q(s′,a′)−Q(s,a)]Q(s,a):=Q(s,a)+\alpha\big[r+\gamma\max_{a^{\prime}}Q(s^{\prime},a^{\prime})-Q(s,a)\big]

Model-free reinforcement learning rule that learns action values from experience.

View details

Discrete Convolution

Advanced
(f∗g)(t)=∑τf(τ) g(t−τ)(f*g)(t)=\sum_{\tau} f(\tau)\,g(t-\tau)

Slides a filter over an input to detect local patterns; the core of CNNs.

View details