Machine learning works by learning patterns from examples instead of having a person write every rule by hand. A learning algorithm gets data and a way to measure its errors. It adjusts the model’s internal settings until the model does well on the examples, and then the model is checked on data it has not seen. The result is a model that makes predictions on new inputs.
Rules written by people versus rules learned from data
Traditional software follows rules that a programmer writes out. A spam filter built that way might flag any email containing certain words. That works when the rules are few and clear.
Machine learning takes a different route. You give the algorithm many emails labeled spam or not spam, and it finds patterns that separate the two groups. The “rules” it ends up with are numbers spread across the model rather than sentences, which is one reason learned models can be hard to read.
Some methods skip building a compact model and instead keep the examples, comparing new inputs against them. This is called instance-based learning, covered in “Instance-Based Learning in Machine Learning With Examples.”
The four ingredients
Every machine learning setup needs:
- Data. Examples, often with labels. The quality and coverage of the data often matter more than the choice of algorithm.
- A model. A function with adjustable parameters, such as a linear model, a decision tree, or a neural network.
- A loss function. A score for how wrong the model’s outputs are on the training examples.
- An optimization method. A procedure that adjusts the parameters to lower the loss. Gradient descent is the most common choice for neural networks.
Training, validation, and testing
Training uses examples to adjust the model. Validation uses a separate set to compare models and choose settings. Testing uses a final held-out set to estimate how the model will handle data it has never seen. Keeping these apart matters, because a model can look accurate on the data it learned from and still do poorly on new data.
Once the model is trained and checked, it is used to make predictions on new inputs. This stage is called inference.
Three main settings
Textbooks usually describe three main types of machine learning, based on the kind of feedback the model gets.
- Supervised learning trains on labeled examples, such as houses described by their features and paired with their sale prices, or emails marked as spam. Its main variants are covered in “Supervised Learning Types With Examples.”
- Unsupervised learning works with unlabeled data and looks for structure, such as groups of similar customers or a smaller set of features that captures most of the variation.
- Reinforcement learning trains an agent through actions and rewards, such as a game-playing system that learns which moves tend to win.
Other setups, such as self-supervised learning, are also used, especially for large language models.
Is machine learning just glorified statistics?
Machine learning draws heavily on statistics, and many of its methods are statistical at their core. Estimating parameters from data, measuring uncertainty, and testing on held-out samples are all statistical ideas.
The differences are mostly in emphasis and scale. Machine learning often focuses on predictive accuracy on new data and uses very flexible models, sometimes with millions or billions of parameters, to capture patterns that would be hard to write down by hand. Whether a given project is better described as statistics or as machine learning is partly a matter of labels, and people reasonably disagree about them.
Where it shows up
Spam filters, product recommendations, speech recognition, and fraud detection are common examples. For more, see “What Are Some Real-Life Examples of Machine Learning?”
Why models fail
A model only knows the patterns in the data it was given, so several things can go wrong:
- Overfitting. The model memorizes noise in the training set and does poorly on new data.
- Biased or unrepresentative data. If some groups or situations are rare in the data, the model may perform worse on them.
- Changing conditions. If real-world inputs drift away from the training data, accuracy can fall even if the model was once good.
No single method wins everywhere
Different problems suit different methods. “The No Free Lunch Rule in Machine Learning” makes the point that, averaged over every possible problem, no method beats the others. In practice, the right method depends on the data, the problem, and what the result has to explain.
The short version
Machine learning finds patterns in examples and uses them to predict on new data. The model is adjusted until it fits the training examples, then tested on data kept aside. It is useful when the data is representative and the problem is well defined, and it is fragile when either is not.