Skip to content
ML to LLMs
Cheat sheets

Important formulas

The formulas worth remembering, with the lesson that derives each.

ConceptFormulaLesson
Dot productx⋅w=∑ixiwix\cdot w = \sum_i x_i w_iVectors
Linear modely^=w⋅x+b\hat{y} = w\cdot x + bLinear regression
MSE1n∑(y−y^)2\frac{1}{n}\sum(y - \hat{y})^2Linear regression
MSE gradients2n∑(y^−y)x\frac{2}{n}\sum(\hat{y}-y)x, 2n∑(y^−y)\frac{2}{n}\sum(\hat{y}-y)Linear regression
Ridge / lasso penaltyλ∑w2\lambda\sum w^2 / λ∑∣w∣\lambda\sum\lvert w\rvertRegularization
Sigmoidσ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z})Logistic regression
Binary cross-entropy−[yln⁡p+(1−y)ln⁡(1−p)]-[y\ln p + (1-y)\ln(1-p)]Logistic regression
Softmax with temperaturepi=ezi/T/∑jezj/Tp_i = e^{z_i/T}/\sum_j e^{z_j/T}Decoding
Precision, recall, F1TPTP+FP\frac{TP}{TP+FP}, TPTP+FN\frac{TP}{TP+FN}, 2PRP+R\frac{2PR}{P+R}Metrics
Bayes' ruleP(A∣B)=P(B∣A)P(A)P(B)P(A\mid B) = \frac{P(B\mid A)P(A)}{P(B)}Probability
Euclidean distance∑(qj−xj)2\sqrt{\sum(q_j - x_j)^2}KNN
Gini impurity / entropy1−∑pk21 - \sum p_k^2 / −∑pklog⁡2pk-\sum p_k\log_2 p_kDecision trees
Boosting updateFm=Fm−1+ηhmF_m = F_{m-1} + \eta h_mEnsembles
K-means objective∑i∥xi−μc(i)∥2\sum_i\lVert x_i - \mu_{c(i)}\rVert^2K-means
PCACv=λvCv = \lambda v; ratio λk/∑λ\lambda_k/\sum\lambdaPCA
TF-IDFTF(t,d)×ln⁡(N/DF(t))\text{TF}(t,d)\times\ln(N/\text{DF}(t))Text to vectors
Cosine similaritya⋅b∥a∥∥b∥\frac{a\cdot b}{\lVert a\rVert\lVert b\rVert}Text to vectors
Layera=f(Wx+b)a = f(Wx + b)Forward pass
Gradient descentθ←θ−η∇θL\theta \leftarrow \theta - \eta\nabla_\theta LGradient descent
Sigmoid + BCE error signal∂L/∂z=y^−y\partial L/\partial z = \hat{y} - yBackpropagation
Conv output size⌊(H−k+2p)/s⌋+1\lfloor (H - k + 2p)/s\rfloor + 1CNNs
Self-attentionsoftmax(QK⊤/dk)V\text{softmax}(QK^\top/\sqrt{d_k})VSelf-attention
Perplexityexp⁡(mean token loss)\exp(\text{mean token loss})Tokenization
LoRAW=W0+αrBAW = W_0 + \frac{\alpha}{r}BAAdapting LLMs
nDCG∑reli/log⁡2(i+1)IDCG\frac{\sum \text{rel}_i/\log_2(i+1)}{\text{IDCG}}LLM evaluation
Little's lawL=λWL = \lambda WProduction architecture