No history yet

Machine Learning Fundamentals

How Machines Learn

Machine learning sounds complex, but the core idea is simple: instead of giving a computer explicit instructions for every task, we give it data and let it figure out the patterns on its own. It's like teaching a child to recognize a cat. You don't list out all the rules—pointy ears, whiskers, four legs, a tail. Instead, you show them lots of pictures of cats. Eventually, they learn to identify a cat they've never seen before.

There are two main ways a machine learns, and it all comes down to the kind of data you give it.

Learning with an Answer Key

The first method is called supervised learning. The "supervised" part means the data we provide is already labeled with the correct answers. It's like giving a student a practice exam that includes an answer key. The goal is for the model to learn the relationship between the questions (the input data) and the answers (the output labels) so it can eventually answer new questions on its own.

Supervised Learning

noun

A type of machine learning where the model learns from data that is labeled with the correct output.

For example, if you want to build a model that predicts house prices, you would feed it a dataset of houses. For each house, you'd provide features like square footage, number of bedrooms, and location. You would also provide the label: the price the house actually sold for. The model's job is to learn the connection between a house's features and its final sale price.

Another common use is classification, like sorting emails into "spam" or "not spam." The model learns from thousands of emails that have already been manually tagged. After training, it can classify new, incoming emails automatically.

This diagram shows a model that has learned to separate two types of labeled data. The line is the boundary it created. Any new data point falling on one side will be classified as a blue circle, and any on the other side will be a pink square.

Finding Patterns on Its Own

What if you don't have an answer key? That's where unsupervised learning comes in. In this approach, we give the model unlabeled data and ask it to find any hidden structures or patterns all by itself. It’s like being handed a giant box of different fruits and being asked to sort them into groups without being told what the fruits are. You might group them by color, size, or shape.

Unsupervised Learning

noun

A type of machine learning where the model works with unlabeled data to find patterns or structures on its own.

A common use for this is customer segmentation. An e-commerce company might use unsupervised learning to group its customers based on their purchasing habits. The model might discover a group of customers who buy frequently but spend little, another group who buys rarely but makes large purchases, and a third that only shops during sales. The business didn't define these groups beforehand; the model found them in the data.

This technique, known as clustering, is useful for discovering new insights you might not have thought to look for.

Here, the model was given a set of unlabeled points. It identified three distinct groups, or clusters, based on how close the points were to each other.

Getting the Right Fit

After a model is trained on a dataset, how do we know if it actually learned something useful? We test it. A standard practice is to split the initial dataset into two or three parts: one for training, and one or two for testing and validation. The model learns from the training data, but its performance is judged on how well it does on the testing data it has never seen before.

This process helps us spot two common pitfalls: underfitting and overfitting.

Imagine a student studying for a history exam. Underfitting is like the student who only reads the first chapter. Their understanding is too simple and they perform poorly on the test because they missed most of the key concepts. An underfit model is too simple to capture the underlying trend in the data.

Overfitting is the opposite problem. It's like a student who memorizes every single question and answer from a practice test. They might get 100% on that specific test, but they'll be stumped by slightly different questions on the real exam. An overfit model learns the training data too well, including its noise and random quirks. It fails to generalize to new, unseen data.

The goal is to find a "good fit"—a model that is complex enough to capture the data's pattern but simple enough to ignore the noise and generalize well to new situations.

Measuring Success

To know if we have a good fit, we need to measure the model's performance with evaluation metrics. The choice of metric depends on the problem you're solving.

For predicting a continuous value like a house price (a regression problem), you might use Mean Absolute Error (MAE). This metric calculates the average of all the absolute differences between the predicted prices and the actual prices. A lower MAE means the model's predictions are, on average, closer to the real values.

MAE=1ni=1nyiy^i\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|

For classification problems like our spam filter, Accuracy is a common starting point. It's simply the percentage of predictions the model got right.

Accuracy = (Number of Correct Predictions) / (Total Number of Predictions)

However, accuracy can be misleading, especially if one class is much more common than another. For instance, if 99% of emails are not spam, a model that always predicts "not spam" would be 99% accurate, but it would be useless because it never catches any actual spam.

In such cases, we use other metrics like Precision (of all the emails we flagged as spam, how many actually were?) and Recall (of all the actual spam emails, how many did we catch?). Balancing these different metrics is key to building a model that performs well in the real world.

Understanding these fundamentals is the first step. By choosing the right learning approach and carefully evaluating performance, you can train models that solve real problems effectively.