Machine Learning Basics

Machine learning is the part of AI where, instead of a person writing down the rules a system should follow, the system works out its own rules by looking at examples.

Hand-coded rules vs. learned patterns

Imagine building a spam filter by hand: you'd write rules like "if the email contains the word 'lottery,' flag it as spam." This breaks down fast — spammers avoid trigger words, legitimate emails sometimes contain them, and the list of rules needed to cover every real case would be endless and constantly out of date. Machine learning takes a different approach entirely: show a system thousands of emails that are already correctly labeled spam or not-spam, and let it work out, statistically, which patterns actually distinguish the two. No one writes the rules; the system infers them from examples.

What "training" actually means

A machine learning model has internal, adjustable numbers called parameters. Training means feeding the model example after example, and after each one, nudging those parameters slightly so the model's output gets a little closer to the correct answer for that example. Repeated over enough examples, the parameters settle into values that capture real patterns in the data — the mechanism behind the tiny worked example in the neural networks lesson coming up is exactly this idea, just for a single neuron.

Training data vs. test data

Here's a mistake that's easy to make and important to avoid: evaluating a model's accuracy on the exact same data it learned from. A model can effectively memorize its training examples rather than learning the underlying pattern, and memorization looks identical to genuine learning if you only ever check performance on data the model has already seen. The standard fix is to split the available data into a training set (what the model learns from) and a separate test set (data the model never sees until evaluation) — a model's real quality is judged by how well it performs on the test set, not the training set.

A concrete example: predicting house prices

Suppose you have a table of house sizes and their sale prices, and you want a model that predicts price from size. Training here just means finding a line through the size/price points that fits them well — the "line" is the model, its slope and intercept are its parameters, and "training" is the process of adjusting slope and intercept until the line's predictions are as close as possible to the actual prices in the training data. A well-trained model then predicts a reasonable price for a house size it has never seen before, based on the pattern it inferred, not a house size it memorized.

Overfitting: a model that scores 100% on its training data isn't necessarily a good model — it may have memorized the noise and quirks specific to those exact examples rather than the actual underlying pattern, a failure called overfitting. An overfit model's performance on new, unseen data (the real test of usefulness) can be far worse than its training-data score suggests, which is exactly why the training/test split exists.