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.

Concepts and formulas

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.

Concepts and formulas

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.

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.

Concepts and formulas

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

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 graded practice exam before the real one.

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 covers the syllabus found in engineering degrees, for example: