What Machine Learning Is and When to Use It
Supervised, unsupervised and reinforcement learning, when a formula beats a model, the project workflow and how to set a baseline.
What machine learning is
A normal program applies rules that a person wrote. A learned model finds its own rules from examples. You provide data (the inputs, often called features) and usually the right answers (the labels), choose a model family (a line, a tree, a neural network), and a training procedure adjusts the model’s parameters until its predictions match the examples. The model is then used on new inputs. For an engineer that is a tool for relationships that are too complex to write down: estimating a quality that cannot be measured directly, recognizing a fault from vibration, or noticing that today’s data looks different from every earlier day.
It is not magic and it is not the only tool. A model can only reproduce patterns that are in its data; it has no understanding of the physics unless you give it some, and it can be confidently wrong on inputs unlike anything it saw. Most of the work (and most of the failures) is in the data, the testing and the deployment, which is why this guide spends more pages there than on algorithms.
The kinds of learning
| Type | Learns from | Typical task | Engineering example |
|---|---|---|---|
| Supervised: regression | Inputs with known numbers | Predict a number | Estimate moisture from dryer temperatures (a soft sensor); remaining life of a bearing |
| Supervised: classification | Inputs with known categories | Predict a category | Pass or fail from a camera image; fault type from vibration |
| Unsupervised: clustering | Inputs without labels | Find groups | Group the operating modes of a machine |
| Unsupervised: anomaly detection | Mostly normal data | Flag the unusual | A pump vibrates differently from its usual self |
| Dimensionality reduction | Inputs without labels | Summarize many inputs by a few | Compress 200 sensor channels into 3 trends for plotting |
| Reinforcement learning | Trial and error with a reward | Learn a policy | A robot learning to walk or grasp, usually in simulation |
| Self-supervised and foundation models | Vast unlabeled data | General representations | A pretrained image or language model fine-tuned on your small data set |
Pages Regression and Curve Fitting and Classification and Metrics cover the supervised tasks; Trees, Clustering and Anomaly Detection covers clustering and anomaly detection; Neural Networks and Deep Learning introduces deep learning.
When to use it, and when not
| Use ML when… | Use a formula, rule or table when… |
|---|---|
| the relationship is too complex or unknown to write down | the physics is known and the equation is accurate enough |
| you have plenty of representative data with answers | you have little data, or only a handful of examples |
| an occasional wrong answer is acceptable and manageable | a wrong answer is dangerous or must be explained to an auditor |
| the pattern is in images, sound or many noisy channels | a threshold, a lookup table or a trend line does the job |
| conditions change slowly and you can retrain | conditions are fixed and well understood |
Worked example: do not model what an equation gives exactly
A 10 kΩ NTC thermistor (B = 3 950 K, 10 kΩ at 25 °C) reads 5 000 Ω. The Beta equation, 1 ÷ T = 1 ÷ T0 + ln(R ÷ R0) ÷ B, gives T = 41.46 °C in one line and needs no data. A neural network trained on a few hundred readings would at best approximate this curve, and would misbehave outside the range it was trained on. Use the equation (see Numerical Methods) and keep ML for what has no equation.
- Physics plus data is stronger than either. Use the equation for the known part and let a model learn the residual, or feed physical quantities (speed, load, temperature) as inputs.
- ML is not a safety function. See the limits on Deployment, Monitoring and Limits.
- Ask whether you can reach the goal without it. A rule that nobody had time to write is not a reason to train a network.
Start from the cost of errors
Before choosing a model, state what each kind of error costs. “95 % accuracy” means nothing until you know what the 5 % costs. In a fault detector a false alarm (stopping a healthy machine) and a miss (running a failing one) rarely cost the same.
Worked example: choosing a detector by cost
Among 10 000 machine-days, 40 are faulty. A false alarm costs $200 (an inspection); a missed fault costs $5 000 (an unplanned stop). Three detectors, differing by how readily they alarm:
| Detector | Faults caught | False-alarm rate | Misses | False alarms | Total cost |
|---|---|---|---|---|---|
| A: sensitive | 95 % | 4.0 % | 2.0 | 398 | $89 680 |
| B: balanced | 85 % | 1.0 % | 6.0 | 100 | $49 920 |
| C: cautious | 60 % | 0.2 % | 16.0 | 20 | $83 984 |
- Detector B: balanced is the cheapest at $49 920, even though it is not the most sensitive. The sensitive one drowns the crew in $79 680 of false alarms; the cautious one lets too many faults through.
- Doing nothing costs 40 × $5 000 = $200 000, so any of these pays for itself. Check this before building anything.
- Moving the alarm threshold moves you along these rows (see Classification and Metrics). Choose the threshold from the costs, not from a default of 0.5.
Always build a baseline
A baseline is the simplest predictor you could use: the average, last week’s value, a rule of thumb, a straight line. It tells you whether the model earns its complexity and gives you a number to beat. Many projects find that the baseline is nearly good enough.
Worked example: predicting moisture from outlet temperature
- Ten dryer runs give outlet temperatures 60, 62, 64, 66, 68, 70, 72, 74, 76, 78 °C and product moisture 14.8, 13.9, 13.5, 12.4, 11.9, 10.8, 10.4, 9.3, 8.9, 8.1 %.
- Baseline: always predict the mean, 11.40 %. Its root-mean-square error is the standard deviation of the data: 2.15 %.
- Model: a least-squares line, moisture = -0.374 × T + 37.20, has an RMS error of 0.15 % and R² = 0.995. That is a 93 % reduction in error over the baseline, for a model you can check by hand.
- At 75 °C it predicts 9.16 %. A more complicated model has to beat this to be worth keeping (see Regression and Curve Fitting and Overfitting, Validation and Tuning).
- These errors are measured on the same ten points the line was fitted to, which flatters it. An honest estimate needs data the model has not seen (see Data Preparation, Splitting and Leakage).
The project workflow
| Step | What you do | Common mistake |
|---|---|---|
| 1. Define the problem | State what to predict, what counts as success and what an error costs | Starting with a method instead of a goal |
| 2. Collect and label data | Gather representative data with the right answers (see Data Logging) | Data from one machine, one season or one operator |
| 3. Clean and explore | Plot it; fix units, gaps and sensor faults; understand it | Skipping straight to modeling |
| 4. Split | Separate training, validation and test data before modeling | Letting test information leak into training |
| 5. Baseline | Build the simplest predictor | Having nothing to compare against |
| 6. Model and tune | Train, compare on the validation set, adjust | Tuning on the test set |
| 7. Evaluate | Measure once on the held-out test set with the right metric | Reporting accuracy on imbalanced data |
| 8. Deploy and monitor | Run it, log inputs and outputs, check for drift | Treating it as finished |
- Spend the time in the early steps. Most improvements come from better data and features, not a fancier model.
- Keep every experiment reproducible: fix random seeds, version the data and code, and record the library versions.
- Write down the plan first (goal, data, metric, baseline, deployment target); it is a one-page document that prevents months of drift.
Tools
| Tool | Use |
|---|---|
| Python, NumPy, pandas | Loading, cleaning and exploring data (see Programming Languages) |
| scikit-learn | Classical ML on tables: regression, trees, clustering, metrics, pipelines |
| PyTorch, TensorFlow / Keras | Neural networks and deep learning |
| Jupyter notebooks | Exploring, documenting and sharing experiments |
| ONNX, TensorFlow Lite, Edge Impulse | Moving trained models to devices (see Deployment, Monitoring and Limits) |
| MLflow, Git, DVC | Tracking experiments, data and model versions |
| OpenCV | Image pre-processing and classic vision (see Robotics Tools) |
# The smallest complete experiment: baseline, then model, on held-out data
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
baseline = np.full_like(y_test, y_train.mean())
model = LinearRegression().fit(X_train, y_train)
rmse = lambda a, b: mean_squared_error(a, b) ** 0.5
print("baseline", rmse(y_test, baseline), "model", rmse(y_test, model.predict(X_test)))
Vocabulary
| Term | Meaning |
|---|---|
| Feature | An input variable (a temperature, an RMS value) |
| Label / target | The answer the model should predict |
| Training, validation, test set | Data to fit the model, to choose between models, and to give the final honest score |
| Parameter | A number the training adjusts (a slope, a weight) |
| Hyperparameter | A setting you choose before training (tree depth, learning rate) |
| Overfitting | Memorizing the training data, noise included, so that new data does badly |
| Inference | Running the trained model on new inputs |
| Drift | The data or the relationship changing after deployment |
Related
- Machine Learning: the overview of this guide.
- Data Preparation, Splitting and Leakage: the next step: preparing and splitting the data.
- Regression and Curve Fitting and Classification and Metrics: the two basic supervised tasks.
- Data Logging: collecting the data.
- Programming Languages: Python and numerical tools.
FAQ
How much data do I need?
It depends on the model and the problem: tens of points for a straight line, hundreds to thousands for a tree model on a table, thousands to millions for a neural network on images (fewer with a pretrained model). Coverage of the real conditions matters more than quantity.
What is the difference between AI and machine learning?
Artificial intelligence is the broad aim of machines doing tasks that seem intelligent. Machine learning is one way to achieve it: learning from data. Deep learning is machine learning with large neural networks.
Do I need a GPU?
Not for classical models on tables or for small networks. A GPU helps when training deep networks on images or large data sets; running a small trained model needs far less.
Can I just use a hosted AI service?
For text, images and speech, often yes, and it may beat a model you train yourself. Check cost, latency, privacy and what happens when the service is offline or changes.
References
- James, G., Witten, D., Hastie, T. and Tibshirani, R., An Introduction to Statistical Learning, Springer (free online).
- Géron, A., Hands-On Machine Learning with Scikit-Learn, Keras and TensorFlow, O’Reilly.
- Zinkevich, M., Rules of Machine Learning: Best Practices for ML Engineering, Google (free online).
Last reviewed: October 2026. Costs and rates in the worked example are illustrative: use your own.
