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.
Contents
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
- Features are what the model receives. The label is the answer we want it to give.
- Supervised learning: the examples have a known answer . Regression gives a number, classification gives a category.
- Unsupervised learning: no answers. For example clustering, which finds groups.
- Training and test sets: the model learns on training data and is measured on test data it has never seen, often split 80/20.
- Overfitting: the model memorizes the training data, noise included, and does poorly on new data.
- Min–max normalization: gives values between 0 and 1.
- Standardization: gives mean 0 and standard deviation 1.
- Mean squared error: .
How to solve the problems
- Work out what is and what is, and whether the answer is a number or a category.
- For normalization: find min and max (or and ) and insert.
- 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?
- , .
- .
Common mistakes
- Testing the model on the same data it was trained on. It then looks much better than it is.
- Normalizing with min and max from the whole dataset, test data included. That leaks information.
- Believing a more complex model is always better. It can easily overfit.
Concepts in this part
2. Linear regression and gradient descent
What is it about?
The simplest model that learns from data is a straight line: . The model adjusts the weight and the intercept 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
- Model: . is the slope, is the intercept with the -axis.
- Loss function: . The goal is to make as small as possible.
- Least squares gives the answer directly:
- Gradient descent: take a small step against the gradient, over and over:
where is the learning rate.
- For MSE, .
- Coefficient of determination between 0 and 1: how much of the variation in the model explains.
How to solve the problems
- Compute the means and .
- Compute the deviations from the mean and insert into the formula for , then .
- For one gradient step: compute the gradient, multiply by and subtract.
Example
The points , and . Find .
- , .
- and .
- , and .
Common mistakes
- Too large a learning rate: the loss jumps back and forth and can blow up. Too small: it takes forever.
- Forgetting the minus sign in the update. We go downhill, towards lower loss.
- Reading a good fit as cause and effect.
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
- The confusion matrix counts four outcomes:
true positive (TP), false positive (FP), true negative (TN) and false negative (FN).
- Accuracy: .
- Precision: . Of those the model said yes to, how many were right?
- Recall: . Of all the real positives, how many did the model find?
- F1 score: , a compromise between precision and recall .
- Logistic regression gives a probability with the sigmoid function . Above a threshold (often 0.5) the model says yes.
- k nearest neighbours (k-NN): a new point gets the class of the majority of the nearest points.
How to solve the problems
- Set up the four numbers TP, FP, TN and FN.
- Pick the right formula: precision looks at the positive answers, recall at the positive cases.
- 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?
- , , .
- Precision . Recall .
Common mistakes
- Trusting accuracy when the classes are imbalanced. If only 1 % is fraud, a model that always says "no" gets 99 %.
- Swapping precision and recall.
- Believing the threshold must be 0.5. A lower threshold gives higher recall but lower precision.
Concepts in this part
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
.
Linear regression and gradient descent: The points , and . What is the slope by least squares?
Answer: 1.5
, . , , so .
Classification and evaluation: TP = 40, FP = 10, FN = 20. What is the precision?
Answer: 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.
Matches these university courses
The content covers the syllabus found in engineering degrees, for example:
- TDT4172 (NTNU)