Advanced Machine Learning
Study hub · Dr. Tariq Mahmood · MS Artificial Intelligence, UMT

Overview

One place for the course: clean notes that combine sir's slides with what he said in class, worked derivations, videos and practice.

Quiz 1
28 Nov 2026
Clean notes
16 pages
Lectures 1 and 2
Videos
30
English and Urdu/Hindi
Practice quiz
8 types
of numerical, new numbers each time

What sir stressed in class

  • "ROC question in Mid." The five-sample ROC question is expected in the midterm. It is page 11 of the clean notes.
  • The class example. TP 83, FN 17, FP 13, TN 87 gives precision 86.46%, recall 83%, accuracy 85%, F1 84.69%.
  • Kaggle for datasets, Keras.io for models.
  • Project rules. Dataset updated in the last two years, and no conference papers, preprints or arXiv as references.

Preparation checklist

Update log

DateChange
27 Nov 2026New tab "Sir's lectures": the original slides of Lecture 1 (51) and Lecture 2 (25), with a link from each slide to its clean notes page.
27 Nov 2026Slides and class notes merged into 16 pages of clean notes. New layout, print view and dark mode.
27 Nov 2026First version: Lectures 1 and 2, eight register pages, calculus, 30 videos, random quiz.

Clean notes

Sir's slides and your class notes, merged in teaching order. Each numbered page is sized to copy onto one register page. Anything tagged Class was said or drawn by sir in class and is not in the slides.

Five corrections already applied to your original register pages
  1. ROC question: sample 5 has probability 0.21. Your first table said 0.29.
  2. ROC question: FP and FN were swapped in several cells. An actual 0 predicted as 1 is FP. An actual 1 predicted as 0 is FN.
  3. ROC question: the slide has six thresholds. Your page missed 0.65, which changes the AUC from 0.8333 to 0.75.
  4. TPR and FPR are worked out for each threshold, not once for the whole table.
  5. Overfit is low bias and high variance.
Lecture 1 · Introduction to machine learning
01
Lecture 1

What machine learning is

Definitions

Machine learningThe science of getting computers to learn and act like humans do, and improve their learning over time in an autonomous fashion, by feeding them data and information in the form of observations and real-world interaction.
Machine learning (short)A type of AI that gives computers the ability to learn without being explicitly programmed. It designs systems that learn and make predictions based on experience (data).
Artificial intelligenceThe simulation of human intelligence processes by machines. The processes are learning, reasoning and self-correction.
Deep learningMachine learning based on artificial neural networks that use multiple layers to extract higher level features from raw input.

The family Class

AI
ML
DL
GenAI

Parts of AI Class

  • AI
    • Classic AI searching
    • ML learns from data
    • DL many-layer neural networks

Traditional programming vs machine learning

Traditional programmingInput + Program = OutputA person writes the rules by hand
Machine learningInput + Output = ProgramThe algorithm produces the program. Program = model

Why we need machine learning

  1. Some programs are very hard to write, such as recognising a face. We do not know how our brain does it.
  2. So we collect many examples that give the correct output for a given input.
  3. A learning algorithm takes the examples and produces a program. It may contain millions of numbers, and if done right it also works on new cases.
Likely questionDefine machine learning. How does it differ from traditional programming?
02
Lecture 1

Key words and data

Key words Class

DatasetThe examples a model learns from. It is generated from the environment.
Validity of datasetTake it from a trusted source. Sir named Kaggle.
FeatureAn input column: what the model looks at.
LabelThe answer column: what the model must predict.
Feature engineeringTurning raw data into useful features.
PredictionThe model's answer for new data.

Data as a table

Think of a spreadsheet. A row is an instance. A column is an attribute (feature).

Attribute 1Attribute 2Attribute 3
Instance 12.22.31
Instance 22.32.60
Instance 32.121

Binary vs multiclass Class

Binary: two classes, such as yes or no. Multiclass: more than two classes.

Tasks solved by learning algorithms

Recognising patternsFaces and expressions, handwritten or spoken words, medical images
Generating patternsImages, motion sequences
Recognising anomaliesUnusual credit card transactions, unusual sensor readings
PredictionFuture stock prices, currency exchange rates
03
Lecture 1

How machine learning works

Four steps

  1. The algorithm is trained on labelled or unlabelled data to produce a model.
  2. New data is given to it, and it predicts based on the model.
  3. Accuracy is checked before deploying.
  4. If the accuracy is not accepted, the machine is trained again and again.

Machine learning workflow

Datasets→Data retrieval→Data preparation→Modeling→Evaluation and tuning→Deployment and monitoring

Data preparation has three parts: data processing and wrangling, feature extraction and engineering, feature scaling and selection. The loop repeats until the model performance is satisfactory.

Process cycle

Data collection→Feature extraction→Feature selection→Model learning→Model evaluation↺

Training and testing data

Training datasetUsed to build and refine the model
Testing datasetUsed to validate the model
New or evaluation datasetThe model's prediction rule is applied to it to give the predicted behaviour

End-to-end pipeline

Data acquisition→Data processing (feature engineering)→Model engineering→Execution→Deployment

What a model does with an input Class

Input→Detect→Recognise / identify→Extract features→Segment / localise→Classify / grade
Likely questionDraw the machine learning workflow, or list the steps of the process cycle.
04
Lecture 1

The three branches of machine learning

The tree Class

  • Machine learning
    • Supervised labelled (annotated) data
      • Regression predicts a number
      • Classification predicts a class
    • Unsupervised unlabelled data, finds similar patterns
      • Clustering ★★★ → group A, ▢▢▢ → group B
    • Reinforcement agent → environment → reward or punishment
      • Q-learning
      • SARSA State-Action-Reward-State-Action

How each one learns

SupervisedTrained on data that is well labelled, meaning it is already tagged with the correct answer. It learns from past data to predict outcomes for unseen data.
UnsupervisedNo supervision. The model works on its own to discover unknown patterns in data that is neither classified nor labelled. Unlabelled data is easier to get than labelled data.
ReinforcementLearns from mistakes. An agent sees a state, takes an action in an environment and gets a reward.

Problems each branch solves

BranchProblemExample
SupervisedClassificationEmail spam detection
RegressionHouse price
RankingSearch engine results
UnsupervisedClusteringCustomer segmentation
SegmentationGrocery store layout
Dimensionality reductionHealth survey reduced to key factors
ReinforcementDecision processSelf-driving cars
Reward systemLoyalty programs
Recommendation systemOnline shopping

Algorithms

SupervisedUnsupervised
1. Linear Regression
2. Logistic Regression
3. Random Forest
4. K-NN
5. Decision Trees
6. Support Vector Machines (SVM)
1. Principal Component Analysis (PCA)
2. Independent Component Analysis (ICA)
3. K-means Clustering
4. Singular Value Decomposition (SVD)
Likely questionDifferentiate supervised, unsupervised and reinforcement learning with one example each.
05
Lecture 1

Deep learning and neural networks

Deep learning

  • Involves a more complex learning process in studying, analysing and classifying data.
  • Suitable for complex data such as language, voice or image.
  • Widely used in image processing.

Simple neural network vs deep learning network

Input layerHidden layersOutput layer
Simple neural networkOneOneOne
Deep learning networkOneManyOne

The basic equation Class

ŷ = w·x + b    ŷ = predicted value,   w = weight,   x = input,   b = bias

Deep learning families Class

  • Deep learning
    • Image based
      • CNN convolutional neural network
        • Pretrained models VGG, DenseNet, ResNet, EfficientNet
    • Text based
      • RNN → NLP
        • BERT
        • Transformer
        • LLM for example ChatGPT

Related terms

Machine reasoning (MR)Systems that generate conclusions from previously acquired knowledge using logical techniques like deduction and induction.
Natural language processing (NLP)A branch of AI that helps computers understand, interpret and manipulate human language.
06
Lecture 1

Python, tools and libraries

Tools

Languages for MLPython, C++, Java, JavaScript, C#, R, Julia, Go, TypeScript, Scala
IDEsPyCharm, Spyder, Jupyter
SetupAnaconda (installs Python and the IDEs). Sir also named TensorFlow Class
Where to get things ClassKaggle for datasets. Keras.io for all models.

Libraries

A library is a collection of pre-written code that can be reused to reduce the time required to code.

Scikit-learnFree ML library for Python, built on SciPy. Algorithms for classification, regression and clustering. Also tools for evaluating models, tuning parameters and pre-processing.
KerasFree, open-source Python library for deep learning. A high-level API developed by Google for implementing neural networks.
from sklearn import svm
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
from keras.layers import Dense
from keras.models import Sequential

Why Python

  1. Very easy to learn and use. Simple syntax.
  2. Code is written and executed faster than in other languages.
  3. Power of a general-purpose language with the ease of MATLAB or R.
  4. Libraries for data loading, visualisation, statistics, NLP and image processing.
  5. Can interact directly with the code using Jupyter, Spyder and notebooks.
  6. Can create complex GUIs and web services.

Python vs C++

In C++ the data type must be declared: int a = 10. In Python it is not: a = 10. Python code is shorter and easier to maintain.

Applications of machine learning

Image recognition, speech recognition, self-driving cars, online fault detection, medical diagnosis, video surveillance, face recognition, traffic prediction, weather prediction, online customer support, online video streaming.

07
Lecture 1

Data preparation

Nine tasks

Data duplicationRemoval of duplicated observations
Dimensionality reductionFind a projection that captures the observations
EncodingTransform data so the modeling methods can use it
Missing dataDelete, estimate, ignore or replace observations
Noise reductionRemove unwanted or clean up polluted observations
OutliersIdentify observations that do not fit the others
Feature selectionRemove redundant or irrelevant attributes
SamplingFind a representative subset
TransformationMap attribute values into a single attribute value

Where the time goes

ActivityShare of time
Cleaning and organising data60%
Collecting data sets19%
Mining data for patterns9%
Refining algorithms4%
Building training sets3%
Other5%
Likely questionList and explain any five data preparation tasks.
Lecture 2 · Evaluation metrics and the maths of training
08
Lecture 2

Four counts and the confusion matrix

Performance evaluation metrics assess how effective a model is. They come in two groups: classification metrics and regression metrics.

Six classification metrics: accuracy, precision, recall (sensitivity), F1 score, area under ROC curve, confusion matrix.

The four counts

CountDefinitionMedical test example
True Positive (TP)Model correctly predicts the positive classA patient who has the disease is identified
True Negative (TN)Model correctly predicts the negative classA patient who does not have the disease is cleared
False Positive (FP)Model predicts positive when the actual class is negativeA healthy patient is told they have the disease
False Negative (FN)Model predicts negative when the actual class is positiveA sick patient is told they do not have the disease

Total instances = TP + TN + FP + FN.

How to never mix them up The second letter is what the model said: P = it said 1, N = it said 0.
The first letter is whether the model was right: T = right, F = wrong.

Confusion matrix

A table that describes the performance of a classification model by comparing actual and predicted values. It gives a complete picture of performance across all classes.

Predicted 1Predicted 0
Actual 1TPFN
Actual 0FPTN

Dataset balance Class

If one class is much larger than the other, accuracy can look high for a poor model. In that case rely on precision, recall and F1.

09
Lecture 2

Accuracy, precision, recall and F1 score

MetricFormulaMeaning
AccuracyTP + TNTotal instancesProportion of correctly predicted instances among all instances
PrecisionTPTP + FPCorrectly predicted positives out of all predicted positives
Recall (sensitivity)TPTP + FNCorrectly predicted positives out of all actual positives
F1 score2 × Precision × RecallPrecision + RecallHarmonic mean of precision and recall

Why the harmonic mean: it corrects extreme values. If either precision or recall is very low, F1 is low even if the other is high. F1 is most useful when the data is imbalanced.

Class example Class

Predicted 1Predicted 0
Actual 1TP = 83FN = 17
Actual 0FP = 13TN = 87
Precision = 8383 + 13 = 8396 = 0.8646 = 86.46%
Recall = 8383 + 17 = 83100 = 0.83 = 83%
Accuracy = 83 + 8783 + 17 + 13 + 87 = 170200 = 85%
F1 = 2 × 0.8646 × 0.830.8646 + 0.83 = 1.43521.6946 = 84.69%

Slide example

TP = 40, FN = 10, FP = 5, TN = 45, tested on 100 data points.

Accuracy = 40 + 45100 = 85%    Precision = 4045 = 88.9%    Recall = 4050 = 80%
F1 = 2 × 88.9 × 8088.9 + 80 = 84.2%
NoteThe slide prints F1 as 84.3%. The exact value is 80 ÷ 95 = 84.21%. Show your working in the exam.
Likely questionGiven a confusion matrix, calculate accuracy, precision, recall and F1 score.
10
Lecture 2

ROC curve and AUC

ROC curve

Receiver Operating Characteristic curve: a graph of the true positive rate against the false positive rate at various threshold settings. It is a tool to evaluate a binary classification model.

True Positive Rate (TPR), also recallTPTP + FNHow well the model identifies positive instances. On the y-axis
False Positive Rate (FPR)FPFP + TNHow often the model wrongly calls a negative instance positive. On the x-axis

How it works: different thresholds are used to classify instances as positive or negative. For each threshold, plot TPR against FPR.

Area under the ROC curve (AUC)

A single number that measures the entire area under the ROC curve and represents the overall performance of the model. Higher is better.

AUCMeaning
1Perfect model: 100% TPR, 0% FPR
0.5No better than random guessing
Above 0.5Better than random. The higher, the better

Why AUC is important

  • Model comparison: useful for comparing models on the same dataset.
  • Threshold independence: evaluates performance across all thresholds, not just one.
11
Lecture 2

ROC and AUC worked question

Sir said in class"ROC question in Mid." Learn this question completely.

Question. A binary classifier gives these probabilities for five samples. Using thresholds T = {0.25, 0.50, 0.65, 0.75, 0.85, 1.00}, find the predicted labels, calculate TPR and FPR, plot the ROC curve and compute AUC.

Sample12345
Actual class (y)11010
Probability (ŷ)0.820.710.530.290.21

Decision rule: predict 1 if probability ≥ threshold, otherwise predict 0.
Actual positives P = 3 (samples 1, 2, 4). Actual negatives N = 2 (samples 3, 5).

Step 1 · Label every sample at every threshold

yŷ0.250.500.650.750.851.00
10.821 TP1 TP1 TP1 TP0 FN0 FN
10.711 TP1 TP1 TP0 FN0 FN0 FN
00.531 FP1 FP0 TN0 TN0 TN0 TN
10.291 TP0 FN0 FN0 FN0 FN0 FN
00.210 TN0 TN0 TN0 TN0 TN0 TN

Step 2 · Count, then find TPR and FPR

TPR = TPTP + FN = TP3      FPR = FPFP + TN = FP2
ThresholdTPFPTNFNTPRFPRPoint (FPR, TPR)
1.00002300(0, 0)
0.85002300(0, 0)
0.7510220.3330(0, 0.333)
0.6520210.6670(0, 0.667)
0.5021110.6670.50(0.5, 0.667)
0.2531101.0000.50(0.5, 1)
End point32001.0001.00(1, 1)

Step 3 · Plot

T = 0.75T = 0.65T = 0.50T = 0.25 00.51 10.6670.333 False Positive Rate (FPR) True Positive Rate (TPR)

Step 4 · AUC by the trapezoidal rule

AUC = Σ TPRi + TPRi+12 × (FPRi+1 − FPRi)

From FPR 0 to 0.5 the height is 0.667:
area = 0.667 × 0.5 = 1/3

From FPR 0.5 to 1 the height is 1:
area = 1 × 0.5 = 1/2

AUC = 13 + 12 = 56 = 0.8333

Interpretation: good discrimination. 5 of the 6 positive-negative pairs are correctly ranked.

Common mistakeUse exactly the thresholds the question gives. Leaving out 0.65 here changes the answer to 0.75.
12
Lecture 2

Regression: actual vs predicted

y = actual value. ŷ = predicted value. On the graph, the vertical distance between a data point and the fitted line is its prediction error.

Residual (error) = actual value − predicted value = y − ŷ

Best fit line, underfit and overfit Class

The best fit line is the line with the smallest total error.

BiasVarianceWhat happens
UnderfitHighLowModel is too simple. Poor on training data and on new data
OverfitLowHighModel memorises the training data. Good on training, poor on new data

Regression metrics

MetricFormulaMeaning
Mean Squared Error (MSE)1n Σ (yi − ŷi)²Average of the squared differences between actual and predicted values
Root Mean Squared Error (RMSE)√MSEError in the same unit as the target variable
Mean Absolute Error (MAE)1n Σ |yi − ŷi|Average of the absolute differences
R-squared (R²)1 − Σ (yi − ŷi)²Σ (yi − ȳ)²Proportion of the variance in the dependent variable that is predictable from the independent variables. Ranges from 0 to 1

ȳ is the mean of the actual values.

Likely questionGiven actual and predicted values, calculate MSE, RMSE and MAE. A practice version is in the quiz tab.
13
Lecture 2

Mathematics for ML, derivatives and partial derivatives

Importance of mathematics in machine learning

AreaRoleApplications
Linear algebraHandling high-dimensional data, such as matrices of image pixelsData transformations, PCA
Probability and statisticsHandling uncertainty and deciding with incomplete informationNaive Bayes classifiers, probabilistic graphical models
CalculusOptimising model parameters during trainingGradient descent, neural network training, backpropagation
OptimisationMinimising loss and finding the best parametersStochastic gradient descent, L2 regularisation

Derivative

The derivative of a function measures how the output changes with respect to a change in its input. In ML, derivatives tell us how to update model parameters to minimise error.

f′(x) = limh→0 f(x + h) − f(x)h      f(x) = ax² + bx + c  →  f′(x) = 2ax + b

Example. Find the derivative of f(x) = 3x² + 5x + 2 at x = 2.

f′(x) = 6x + 5   →   f′(2) = 6(2) + 5 = 12 + 5 = 17

Partial derivative

Measures how a multivariable function changes as one variable changes while the others are kept constant. It is crucial for models that depend on multiple parameters.

Example. f(x, y) = x² + y² at the point (2, 3).

∂f∂x = 2x = 2(2) = 4      ∂f∂y = 2y = 2(3) = 6

Link to ML: gradient descent uses partial derivatives to optimise several parameters at once. Each parameter is adjusted by its own partial derivative.

14
Lecture 2

Gradient descent and stochastic gradient descent

Training workflow

Training data→ML model→Loss function→Gradient descent→Model evaluation

Gradient descent sends an update back to the model, and the loop repeats. Loss guides the parameter updates. Evaluation measures model performance.

Gradient descent on a simple function

f(x) = x² + 3x + 2, so f′(x) = 2x + 3. Start at x = 10 with learning rate 0.1.

x = x − learning rate × gradient
IterationGradient = 2x + 3New x
02(10) + 3 = 2310 − 0.1(23) = 7.7
12(7.7) + 3 = 18.47.7 − 0.1(18.4) = 5.86
22(5.86) + 3 = 14.725.86 − 0.1(14.72) = 4.388

Stochastic gradient descent (SGD)

A popular optimisation algorithm for minimising the cost (loss) function in machine learning.

Batch gradient descentStochastic gradient descent
Data used per updateThe entire datasetOne data point at a time
SpeedSlower on large datasetsOften converges faster, especially on large datasets

How SGD works

  1. Initialise parameters: start with random values for the model parameters.
  2. Iterate over data: for each data point, calculate the gradient of the cost function with respect to the parameters, then move the parameters in the opposite direction of the gradient.
  3. Repeat for multiple epochs until the algorithm converges to the minimum or stops improving.
Likely questionDifferentiate batch gradient descent and SGD. Explain how SGD works.
15
Lecture 2

Numerical example of SGD

Problem. Fit a line ŷ = w·x + b, where w is the weight, b is the bias and x is the input feature.
Data points: (x₁, y₁) = (1, 2) and (x₂, y₂) = (2, 3). Initialise w = 0, b = 0, learning rate α = 0.1.

Loss for one data point: L = (y − ŷ)²    y = true value, ŷ = predicted value

Gradients by the chain rule

Loss with respect to ŷ∂L∂ŷ = 2(y − ŷ)(0 − 1) = −2(y − ŷ)
ŷ with respect to w∂ŷ∂w = x
ŷ with respect to b∂ŷ∂b = 1
Chain rule for w∂L∂w = ∂L∂ŷ × ∂ŷ∂w = −2(y − ŷ) × x
Chain rule for b∂L∂b = ∂L∂ŷ × ∂ŷ∂b = −2(y − ŷ)
Update rule: coefficient = coefficient − (alpha × delta)    delta is the derivative

Calculation

StepData point (1, 2)Data point (2, 3)
Predicted value ŷ = w·x + b0·1 + 0 = 00.4 × 2 + 0.4 = 1.2
Loss L = (y − ŷ)²(2 − 0)² = 4(3 − 1.2)² = 3.24
∂L/∂w = −2(y − ŷ) × x−2(2 − 0) × 1 = −4−2(3 − 1.2) × 2 = −7.2
∂L/∂b = −2(y − ŷ)−2(2 − 0) = −4−2(3 − 1.2) = −3.6
w = w − α × (∂L/∂w)0 − 0.1(−4) = 0.40.4 − 0.1(−7.2) = 0.4 + 0.72 = 1.12
b = b − α × (∂L/∂b)0 − 0.1(−4) = 0.40.4 − 0.1(−3.6) = 0.4 + 0.36 = 0.76
After both data points: w = 1.12, b = 0.76
Common mistakeThe gradient is negative. Minus a negative is plus, so w and b go up.
Likely questionPerform one or two SGD updates for a given data point, starting values and learning rate. Every step is explained slowly in the Calculus explained tab.
Class instructions
16
Class instructions

Project rules and tools from sir

Kaggle accountMake one. Datasets come from Kaggle.
Dataset ageUpdated in the last two years (after 2024), as written in your register.
Do not take1. Conference papers   2. Preprints   3. arXiv
ModelsKeras.io lists all models.
Writing the paperOverleaf.
To confirm with sirYour note reads as "use a recently updated dataset and cite journal papers only". Check that this is what he meant, because it affects your project's dataset and reference list.

Original register photos are in the register folder next to this file.

Sir's lectures

The original slides, exactly as sir showed them. Move with the buttons or the ← and → keys. Under each slide is a link to the clean notes page that covers it.

 ·  Open the PDF

Some slides in sir's file show only a heading, and the picture for it comes on the next slide. That is how the file is.

Calculus explained

The derivations from Lecture 2, taken one small step at a time. Read this to understand; copy the short version from the clean notes.

NoteYour register does not show which derivation sir set in class. This tab covers every derivation in his Lecture 2 slides. If his problem was different, tell me what it was and it will be added.

1. What a derivative is

A derivative answers one question: if I change the input a little, how much does the output change? It is the slope of the curve at one point.

Derivative isThe curve isTo make the output smaller
PositiveGoing upMove the input down
NegativeGoing downMove the input up
ZeroFlatStop: this is the bottom

In machine learning the output is the loss (how wrong the model is) and the input is a weight. The derivative tells us which way to move the weight so the loss gets smaller.

2. The four rules you need

RuleIn symbolsExample
A constant becomes 0d/dx (c) = 0d/dx (7) = 0
Power rule: bring the power down, reduce it by 1d/dx (xⁿ) = n·xⁿ⁻¹d/dx (x²) = 2x  and  d/dx (x) = 1
A number in front staysd/dx (a·xⁿ) = a·n·xⁿ⁻¹d/dx (3x²) = 6x  and  d/dx (5x) = 5
Do each term separatelyd/dx (f + g) = f′ + g′d/dx (3x² + 5x + 2) = 6x + 5 + 0

3. Slide example: f(x) = 3x² + 5x + 2 at x = 2

  1. Take each term: 3x² → 6x.   5x → 5.   2 → 0.
  2. Add them: f′(x) = 6x + 5.
  3. Put x = 2: f′(2) = 6(2) + 5 = 12 + 5 = 17.

4. Where the power rule comes from

The slide gives the definition below. The blackboard picture in the slides shows this same working.

f′(x) = limh→0 f(x + h) − f(x)h

Meaning: take a tiny step h, see how much f changed, divide by the step, then let the step shrink to zero.

For f(x) = x²

  1. f(x + h) = (x + h)² = x² + 2xh + h²
  2. f(x + h) − f(x) = x² + 2xh + h² − x² = 2xh + h²
  3. Divide by h: 2xh + h²h = 2x + h
  4. Let h go to 0: 2x + 0 = 2x

For f(x) = ax² + bx + c

  1. f(x + h) = a(x + h)² + b(x + h) + c = ax² + 2axh + ah² + bx + bh + c
  2. f(x + h) − f(x) = 2axh + ah² + bh   (ax², bx and c cancel)
  3. Divide by h: 2ax + ah + b
  4. Let h go to 0: 2ax + b

5. Partial derivatives

When a function has two inputs, change one and treat the other as a fixed number. The symbol is ∂ in place of d.

Slide example: f(x, y) = x² + y² at the point (2, 3).

  1. ∂f/∂x: treat y as a constant. x² → 2x, and y² → 0. So ∂f/∂x = 2x.
  2. At (2, 3): 2(2) = 4.
  3. ∂f/∂y: treat x as a constant. x² → 0, and y² → 2y. So ∂f/∂y = 2y.
  4. At (2, 3): 2(3) = 6.

6. The chain rule

Use it when one thing depends on a second, and the second depends on a third. Here the loss L depends on the prediction ŷ, and ŷ depends on the weight w.

∂L∂w = ∂L∂ŷ × ∂ŷ∂w

In words: (how the loss changes with the prediction) × (how the prediction changes with the weight).

7. The main derivation: gradients for SGD

Given: ŷ = w·x + b and L = (y − ŷ)².   Wanted: ∂L/∂w and ∂L/∂b.

Part A · How the loss changes with the prediction

  1. Call the inside part u = y − ŷ. Then L = u².
  2. Power rule: dL/du = 2u = 2(y − ŷ).
  3. Differentiate the inside with respect to ŷ: y is a constant → 0, and −ŷ → −1. So du/dŷ = −1.
  4. Multiply: ∂L/∂ŷ = 2(y − ŷ) × (−1) = −2(y − ŷ).

The slide writes step 3 as "(0 − 1)". It is the same thing: 0 from y and −1 from −ŷ.

Part B · How the prediction changes with w and with b

  1. ŷ = w·x + b. For w: w·x → x, and b is a constant → 0. So ∂ŷ/∂w = x.
  2. For b: w·x is a constant → 0, and b → 1. So ∂ŷ/∂b = 1.

Part C · Multiply

∂L∂w = −2(y − ŷ) × x       ∂L∂b = −2(y − ŷ) × 1 = −2(y − ŷ)

Part D · Update the parameters

new w = w − α × ∂L∂w       new b = b − α × ∂L∂b

α is the learning rate. We subtract because the gradient points uphill and we want to go downhill.

8. The same derivation with numbers

Data points (1, 2) and (2, 3). Start with w = 0, b = 0, α = 0.1.

StepData point (1, 2)Data point (2, 3)
Prediction ŷ = w·x + b0·1 + 0 = 00.4·2 + 0.4 = 1.2
Loss (y − ŷ)²(2 − 0)² = 4(3 − 1.2)² = 3.24
∂L/∂w = −2(y − ŷ)·x−2(2)(1) = −4−2(1.8)(2) = −7.2
∂L/∂b = −2(y − ŷ)−2(2) = −4−2(1.8) = −3.6
New w0 − 0.1(−4) = 0.40.4 − 0.1(−7.2) = 1.12
New b0 − 0.1(−4) = 0.40.4 − 0.1(−3.6) = 0.76

Final: w = 1.12, b = 0.76. The loss fell from 4 to 3.24 after one update, which shows the model is improving.

Formula sheet

Every formula from Lectures 1 and 2 on one page. Use the Print button for a paper copy.

Classification

Accuracy = TP + TNTP + TN + FP + FN
Precision = TPTP + FP      Recall (sensitivity, TPR) = TPTP + FN
F1 score = 2 × Precision × RecallPrecision + Recall
TPR = TPTP + FN      FPR = FPFP + TN
AUC = Σ TPRi + TPRi+12 × (FPRi+1 − FPRi)

Regression

Residual = y − ŷ
MSE = 1n Σ (yi − ŷi)²     RMSE = √MSE     MAE = 1n Σ |yi − ŷi|
R² = 1 − Σ (yi − ŷi)²Σ (yi − ȳ)²

Calculus and gradient descent

f′(x) = limh→0 f(x + h) − f(x)h      f(x) = ax² + bx + c → f′(x) = 2ax + b
f(x, y) = x² + y²  →  ∂f/∂x = 2x,   ∂f/∂y = 2y
Gradient descent: x = x − α × f′(x)
Model: ŷ = w·x + b      Loss: L = (y − ŷ)²
∂L/∂w = −2(y − ŷ)·x      ∂L/∂b = −2(y − ŷ)
w = w − α × ∂L/∂w      b = b − α × ∂L/∂b

Facts to remember

ProgrammingTraditional: Input + Program = Output. ML: Input + Output = Program.
ROC axesFPR on the x-axis, TPR on the y-axis.
AUC1 is perfect. 0.5 is random guessing.
FitUnderfit: high bias. Overfit: low bias, high variance.
Gradient descentBatch uses all the data per update. SGD uses one data point.
DataRow = instance. Column = attribute (feature).

Videos

Widely watched, beginner-friendly videos for each topic. View counts were checked on YouTube on 27 Nov 2026. Each card opens YouTube in a new tab.

Practice quiz

Every quiz is different, and numericals get new numbers each time. Solve on paper first, then open the solution.