What machine learning is (and is not)
Learning patterns from examples instead of writing rules, and when that is the right tool.
Lesson 1 of 6610 minBeginner
You will learn to
- Explain the difference between rules and learned models
- Name the main kinds of ML problems
- Recognise problems ML should not be used for
Intuition
Think about how you would teach a child to recognise a dog. You do not hand over a rulebook ("four legs, fur, a tail, but not a cat"). You point at many animals and say "dog" or "not a dog", and the child works out the pattern. Machine learning works the same way.
In ordinary programming, a person writes the rules and the computer applies them to data to produce answers. In machine learning the roles change: you give the computer data and the answers that went with it, and a learning algorithm finds the rules. The result is called a model: a function that takes the inputs of a new case and returns a prediction.
This is useful because many rules are too complex or too fuzzy to write by hand. Nobody can list the exact conditions that make a customer likely to leave, a loan likely to default or an email likely to be spam. But you may have thousands of past cases where the outcome is known.
Machine learning is also less magical than it sounds. A model finds patterns that were already in its examples. If the examples are biased, too few or not like the future, the model will be too. It does not understand, it does not know what it has not seen, and it is never certain.
Picture it
The main kinds of problems differ in what the examples look like:
| Kind | What you have | What you predict | Example |
|---|---|---|---|
| Classification | Past rows with a category | A category | Will this customer leave: yes or no? |
| Regression | Past rows with a number | A number | What is the price of this house? |
| Time series forecasting | A series of numbers over time | Future values | How many units will we sell next week? |
| Clustering | Rows with no answer column | Groups of similar rows | Which customers behave alike? |
| Anomaly detection | Rows, mostly normal | Which rows look unusual | Which transactions look odd? |
The first three are supervised: every training row comes with the right answer. The last two are unsupervised: there is no answer column, and the algorithm looks for structure by itself.
The math
The idea fits in one line. Suppose each case has inputs and a known answer . A model is a function that maps inputs to a prediction . Learning means choosing, from a family of candidate functions, the one with the smallest total error on the examples:
Here is the number of examples, is the -th example, and the squared difference measures how far the prediction is from the answer. Other problems use other measures of error, but the structure is always the same: define a family of functions, define an error, pick the function that makes the error small.
The simplest family is a straight line, . "Learning" then means finding the two numbers and . Real models have many more adjustable numbers, but nothing else changes.
One caution: small error on the examples is not the goal. The goal is small error on new cases. The lesson on overfitting explains why those two can differ a lot.
Worked example
Take five apartments (the numbers are made up for illustration): area in square metres and asking price in thousands.
| Area (m²) | 50 | 60 | 80 | 100 | 110 |
|---|---|---|---|---|---|
| Price (thousands) | 150 | 170 | 230 | 270 | 300 |
A hand-written rule might say: "a flat costs 3 thousand per square metre". It does not fit the data: it predicts 150 for 50 m², which is right, but 300 for 100 m², where the data say 270, and 330 for 110 m², where the data say 300.
A learned rule picks and to minimise the squared error on these five rows. Solving it gives and , so . The predictions are 149, 174, 224, 274 and 299, and the errors against the real prices are 1, -4, 6, -4 and 1. The mean squared error is , a typical miss of about 3.7 thousand.
Now a new 90 m² apartment arrives. The model answers thousand. That is machine learning in miniature: the rule (24 plus 2.5 per square metre) was not written by a person; it was found from examples, and it was then applied to a case the model had never seen. It is also a reminder that five rows is a very thin basis. The model would be badly wrong for a 400 m² villa, because nothing like it was in the examples.
How mlflow does it
mlflow covers the five kinds of problems in the table above. In Pipelines you choose the task when you create a pipeline: Classification, Regression, Clustering, Anomaly detection or Time series forecasting.
The Use cases page offers four ready-made starting points, each built from a bundled sample dataset:
- Churn prediction: classification, target
left. - Price regression: regression, target
Price. - Credit default risk: classification, target
default. - Customer segmentation: clustering, no target column.
Choosing Use this template creates a project, a dataset and a pipeline in one go, which is a quick way to see each kind of problem end to end.
Common mistakes
- Using ML where a rule is known. If the rule is exact and written down (a tax rate, a unit conversion, a business policy), code is simpler, cheaper and always right. Use learning for patterns you can show but not state.
- Using ML with no examples. A supervised model needs past cases with known answers. If you have never recorded the outcome, collecting it is the first project, not training.
- Expecting certainty. A model returns a best guess based on past patterns. Plan for the errors it will make instead of hoping for none.
- Forgetting that the world changes. A model learned from last year's examples describes last year. If customers, prices or sensors change, the patterns can stop holding, so results must be watched after launch.
- Treating the output as a cause. A model that predicts churn from past behaviour does not say why customers leave. Prediction and explanation are different jobs.
- Using it where a wrong answer is unacceptable and cannot be checked. For high-stakes decisions a model can still help, but only inside a process where a person or a rule can catch its mistakes.
Try it in mlflow
Browse the use-case gallery
- Open Use cases (Start from a use case).
- Read the four templates: for each one, note the task, the sample dataset and the target column.
- Decide which template has no answer column, and what that means for what it can find.