All courses › Machine Learning and Data Analysis

Machine Learning and Data Analysis (ML): free practice, theory and problems

Machine learning means letting the computer find patterns in data instead of us writing the rules. You give the model many examples, and it learns a relationship it can apply to new cases: spotting faults on a production line, estimating tomorrow's power use or sorting email.

3 parts37 problems9 concepts explainedPractice examFree
Start practising for free →

Contents

  1. Data and core concepts
  2. Linear regression and gradient descent
  3. Classification and evaluation

1. Data and core concepts

What is it about?

Machine learning means letting the computer find patterns in data instead of us writing the rules. You give the model many examples, and it learns a relationship it can apply to new cases: spotting faults on a production line, estimating tomorrow's power use or sorting email.

In short

What is machine learning?

In ordinary programming we write the rules ourselves. In machine learning we give the computer examples, and it finds the rules – a model – by adjusting parameters so that the error is as small as possible. Three main forms:

Data matter most

"Garbage in, garbage out." Most of the work in an ML project is collecting, cleaning and understanding the data:

Training, validation and test

The data are split into a training set (the model learns), a validation set (choosing model and hyperparameters) and a test set (one final, honest assessment). Test data must never be used during development – otherwise you only measure how well the model has memorised the test set. Cross-validation rotates which part is used for validation and gives a more stable estimate when data are scarce. Also watch out for data leakage: information from the future or from the target sneaking into the features.

Under- and overfitting

This is the bias–variance trade-off: simple models have high bias, complex ones high variance. The goal is the balance that gives the lowest error on new data.

How to solve the problems

  1. Work out what xx is and what yy is, and whether the answer is a number or a category.
  2. For normalization: find min and max (or μ\mu and σ\sigma) and insert.
  3. For error measures: compute the error for each point, square it, and take the mean.

Example

The temperatures 10, 15 and 30 °C are to be min–max normalized. What does 15 become?

  1. xmin=10x_{min} = 10, xmax=30x_{max} = 30.
  2. x′=(15−10)/(30−10)=5/20=0.25x' = (15 - 10)/(30 - 10) = 5/20 = 0.25.

Common mistakes

Train on training data, measure on test data. Regression → number, classification → category. z=(x−μ)/σz = (x-\mu)/\sigma.

Concepts in this part

Practise data and core concepts in the app →

2. Linear regression and gradient descent

What is it about?

The simplest model that learns from data is a straight line: y^=wx+b\hat y = wx + b. The model adjusts the weight ww and the intercept bb so the line fits the points as well as possible. Exactly the same idea, just with many more weights, is behind large neural networks.

In short

w=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2,b=yˉ−wxˉw = \dfrac{\sum (x_i - \bar x)(y_i - \bar y)}{\sum (x_i - \bar x)^2}, \qquad b = \bar y - w\bar x
w←w−η ∂L∂ww \leftarrow w - \eta\,\dfrac{\partial L}{\partial w}

where η\eta is the learning rate.

From one to many variables

With several features the model becomes y^=w1x1+w2x2+⋯+wdxd+b\hat y = w_1 x_1 + w_2 x_2 + \dots + w_d x_d + b, compactly y^=wTx+b\hat y = \mathbf{w}^T \mathbf{x} + b. Each weight says how much y^\hat y changes when that feature increases by one while the others are held fixed. Polynomial regression adds features such as x2x^2 and x3x^3 and can then fit curves – but the model is still linear in the weights, so the same methods work.

Why squared error?

MSE punishes large errors much harder than small ones, is smooth and has a single minimum for linear regression (the loss surface is a "bowl"). The downside is that outliers have great influence. MAE (mean absolute error) is more robust. The square root of MSE, RMSE, has the same unit as yy and is easier to interpret.

Gradient descent in practice

The gradient points in the direction where the loss rises fastest; we go the opposite way. Variants:

An epoch is one pass through the whole training set. Watch a loss curve for training and validation: if training loss falls while validation loss rises, the model is overfitting.

The learning rate

The learning rate η\eta is the most important hyperparameter. Too large: the loss oscillates or diverges. Too small: training crawls. Common practice is to start at, say, 0.01 and try ten times larger and smaller, or let η\eta decay during training. Scaling the features makes the bowl rounder and gradient descent far more efficient.

Regularisation

From regression to neural networks

A neural network is many linear layers with a non-linear activation function (such as ReLU) in between. Gradients are computed by backpropagation (the chain rule), and the weights are updated with exactly the same gradient descent as here.

How to solve the problems

  1. Compute the means xˉ\bar x and yˉ\bar y.
  2. Compute the deviations from the mean and insert into the formula for ww, then bb.
  3. For one gradient step: compute the gradient, multiply by η\eta and subtract.

Example

The points (1,2)(1, 2), (2,4)(2, 4) and (3,5)(3, 5). Find ww.

  1. xˉ=2\bar x = 2, yˉ=11/3\bar y = 11/3.
  2. ∑(x−xˉ)(y−yˉ)=(−1)(−5/3)+0+(1)(4/3)=3\sum (x-\bar x)(y-\bar y) = (-1)(-5/3) + 0 + (1)(4/3) = 3 and ∑(x−xˉ)2=2\sum (x-\bar x)^2 = 2.
  3. w=3/2=1.5w = 3/2 = 1.5, and b=11/3−1.5⋅2≈0.667b = 11/3 - 1.5\cdot 2 \approx 0.667.

Common mistakes

y^=wx+b\hat y = wx + b. Minimize MSE. w←w−η ∂L/∂ww \leftarrow w - \eta\,\partial L/\partial w.

Concepts in this part

Practise linear regression and gradient descent in the app →

3. Classification and evaluation

What is it about?

A classification model says "yes" or "no": is the part defective, is the tumour malignant, is the transaction fraud? To know whether the model is good, we must count where it hits and where it misses. And we must choose how strict it should be.

In short

true positive (TP), false positive (FP), true negative (TN) and false negative (FN).

Logistic regression

For classification we need a probability between 0 and 1. Logistic regression passes the linear combination through the sigmoid function σ(z)=11+e−z\sigma(z) = \dfrac{1}{1 + e^{-z}}. If the probability is above a threshold (often 0.5), class 1 is chosen. The model is trained by minimising cross-entropy (log loss), which punishes confident mistakes hard. With many classes, softmax is used.

Other classifiers

The confusion matrix

For two classes we count true positives (TP), false positives (FP), true negatives (TN) and false negatives (FN). From these:

When accuracy misleads

With imbalanced classes accuracy is misleading. If 1 % of transactions are fraud, a model that always says "not fraud" gets 99 % accuracy – and finds nothing. Then you must look at precision, recall and F1, and perhaps weight the classes or change the threshold.

Threshold and ROC

Lowering the threshold gives more positives: higher recall but lower precision. What is right depends on the cost of errors: in cancer screening a missed case (FN) is much worse than an extra check (FP); in a spam filter it is worse to discard an important email (FP). The ROC curve shows recall against false positive rate for all thresholds, and the AUC (area under it) summarises how well the model separates the classes – 0.5 is random guessing, 1 is perfect.

Responsible use

Models can amplify biases in the data and make decisions that affect people. Evaluate performance for different groups, be open about limitations, and let humans have the final say in important decisions. The EU AI Act sets specific requirements for high-risk systems.

How to solve the problems

  1. Set up the four numbers TP, FP, TN and FN.
  2. Pick the right formula: precision looks at the positive answers, recall at the positive cases.
  3. Think about what is worse: a false alarm or a missed case?

Example

A model finds 40 of 50 defective parts and raises a false alarm on 10 good parts. Precision and recall?

  1. TP=40TP = 40, FN=10FN = 10, FP=10FP = 10.
  2. Precision =40/50=0.8= 40/50 = 0.8. Recall =40/50=0.8= 40/50 = 0.8.

Common mistakes

Precision = TP/(TP+FP), recall = TP/(TP+FN). Imbalanced classes → do not trust accuracy alone.

Concepts in this part

Practise classification and evaluation in the app →

Example problems with solutions

Here are some of the problems in machine Learning and Data Analysis. In the app, calculation problems get new numbers every time, so you can practise until it sticks – and take a practice exam with an indicative grade as you prepare for the exam.

Data and core concepts: The temperatures 10, 15 and 30 °C are min–max normalized. What does 15 become?

Answer: 0.25

x′=(15−10)/(30−10)=5/20=0.25x' = (15-10)/(30-10) = 5/20 = 0.25.

Linear regression and gradient descent: The points (1,2)(1, 2), (2,4)(2, 4) and (3,5)(3, 5). What is the slope ww by least squares?

Answer: 1.5

xˉ=2\bar x = 2, yˉ=11/3\bar y = 11/3. ∑(x−xˉ)(y−yˉ)=3\sum (x-\bar x)(y-\bar y) = 3, ∑(x−xˉ)2=2\sum (x-\bar x)^2 = 2, so w=3/2=1.5w = 3/2 = 1.5.

Classification and evaluation: TP = 40, FP = 10, FN = 20. What is the precision?

Answer: 0.8

P=TP/(TP+FP)=40/50=0.8P = TP/(TP+FP) = 40/50 = 0.8.

Data and core concepts: A model is to estimate the price of a home. What kind of task is it?

Answer: Regression

The answer is a number (a price), and we have examples with known answers. It is supervised regression.

Practise all the problems →

Matches these university courses

The content follows the syllabus found in, for example: