How Machines Learn From Data

Created by eneaslari 16/7/2026

AI series

Computers are often described as machines that follow instructions. In traditional programming, a developer writes rules that tell a computer exactly what to do. For example, a programmer might create a rule stating that an email should be marked as spam when it contains certain suspicious words.

Machine learning works differently.

Instead of being manually programmed with a separate rule for every possible situation, a machine-learning system learns patterns from examples. By studying past data, it develops a model that can make predictions about new situations.

This data-driven approach is the central idea of machine learning.

From Rules to Examples

Imagine that you want a computer to predict whether a student will pass an exam.

A traditional program might use rules such as:

  • If the student studies more than five hours, predict “pass.”
  • If attendance is below 50 percent, predict “fail.”
  • If the previous grade is high, predict “pass.”

However, real situations are rarely this simple. A student may study for many hours but attend few classes. Another student may have strong attendance but a low previous grade. Creating rules for every possible combination would quickly become difficult.

A machine-learning system takes another approach. It examines examples of students whose final results are already known. It then searches for relationships between factors such as study time, attendance, previous grades, and exam results.

The system is not told every rule. It learns useful patterns from the data.

What Is a Dataset?

A dataset is an organized collection of information used by a machine-learning system.

A dataset is often presented as a table. Each row represents one example, while each column contains a particular type of information.

Consider this small student dataset:

Student Study Hours Attendance Previous Grade Result
A 2 55% 48 Fail
B 5 80% 67 Pass
C 7 92% 78 Pass
D 3 65% 54 Fail
E 6 88% 72 Pass
F 4 75% 61 Pass

Each student is an example. The dataset gives the machine several examples from which it can learn.

Large machine-learning systems may learn from thousands, millions, or even billions of examples. However, the basic principle remains the same: the model studies past examples to find patterns that may be useful in the future.

Features and Labels

The information used to describe each example is divided into features and labels.

Features

Features are the pieces of information the model uses to make a prediction.

In the student dataset, the features are:

  • Study hours
  • Attendance
  • Previous grade

These features may contain useful clues about whether a student is likely to pass.

Labels

A label is the outcome the model is expected to predict.

In this example, the label is the student’s final result:

  • Pass
  • Fail

Because the correct results are already included in the training data, the model can compare its predictions with the real answers and improve.

What Happens During Training?

The process of learning from data is called training.

During training, the machine-learning model examines the examples in the dataset. It searches for patterns connecting the features to the labels.

For instance, it might notice that students with strong attendance, higher previous grades, and more study hours are more likely to pass. It may also discover that no single feature determines the outcome by itself. Instead, several features may work together.

The model adjusts its internal calculations as it learns. Each adjustment is intended to reduce the difference between its predictions and the known answers in the training data.

The final result of this process is a trained model.

A model is not simply a list of facts from the dataset. It is a mathematical representation of the patterns found within those facts.

Making a Prediction

After training, the model can receive a new example that was not included in the original dataset.

Suppose a new student has the following information:

Study Hours Attendance Previous Grade
5 85% 69

The model compares this combination of features with the patterns it learned during training. It may then predict that the student will pass.

This output is called a prediction.

A prediction is not guaranteed to be correct. It is the model’s best estimate based on the information and patterns available to it.

Pattern Learning

Machine-learning models are designed to identify relationships that may be difficult to express as simple rules.

A model might learn that high attendance is especially important for students with lower previous grades. It might discover that study hours have a stronger effect after a certain point. More advanced models can identify extremely complicated relationships across hundreds or thousands of features.

This process is called pattern learning.

However, the model does not understand these patterns in the same way a person does. It uses mathematical relationships to calculate likely outcomes. The quality of those calculations depends heavily on the quality of the data used for training.

Generalization: Learning Beyond the Training Data

A useful model must do more than remember its training examples. It must perform well on new examples.

This ability is called generalization.

Suppose a model correctly predicts the result of every student in its training dataset but performs poorly when given information about new students. Such a model has memorized the training data rather than learning a reliable pattern.

Good generalization means that the model has learned relationships that apply beyond the examples it has already seen.

To measure generalization, machine-learning developers usually divide their data into separate groups. One group is used for training, while another is used for testing. The testing data contains examples the model did not see during training.

If the model performs well on the unseen testing data, it is more likely to work successfully in the real world.

Real-World Examples of Machine Learning

The same learning process can be applied to many different problems.

Predicting House Prices

A house-price model can learn from previous property sales.

Its features might include:

  • Property size
  • Number of bedrooms
  • Location
  • Building age
  • Distance from schools or public transport

The label would be the final sale price.

After training, the model could estimate the price of a new property based on its features.

Classifying Spam Emails

A spam-detection model can learn from emails that have already been marked as spam or legitimate.

Its features might include:

  • Words in the subject line
  • Number of links
  • Sender information
  • Unusual formatting
  • Frequency of certain phrases

The label would be either “spam” or “not spam.”

The trained model could then classify new emails as they arrive.

Detecting Defective Products

In a factory, a machine-learning model can examine information about products that passed or failed quality checks.

Its features might include:

  • Product measurements
  • Machine temperature
  • Production speed
  • Material quality
  • Images of the finished product

The label would indicate whether the product is defective.

The model could help identify quality problems earlier and reduce waste.

Predicting Student Performance

Schools may use historical information to identify students who could benefit from additional support.

Features might include:

  • Attendance
  • Assignment scores
  • Previous grades
  • Participation
  • Study activity

The label might show whether a student passed a course, completed a program, or required extra assistance.

Such predictions should be used carefully. A model should support human decision-making rather than unfairly limiting a student’s opportunities.

Practical Activity: Learn From a Tiny Dataset

Return to the student dataset:

Student Study Hours Attendance Previous Grade Result
A 2 55% 48 Fail
B 5 80% 67 Pass
C 7 92% 78 Pass
D 3 65% 54 Fail
E 6 88% 72 Pass
F 4 75% 61 Pass

Study the rows and look for patterns.

You may notice that the students who passed generally had better attendance, higher previous grades, or more study hours. Students A and D had lower values across most of the features and did not pass.

Now consider three new students:

Student Study Hours Attendance Previous Grade
G 6 90% 74
H 2 60% 50
I 4 82% 65

Based on the original examples, what result would you predict for each student?

A reasonable prediction might be:

  • Student G: Pass
  • Student H: Fail
  • Student I: Pass

By making these predictions, you are performing a simple form of pattern learning. You are using previous examples to estimate an unknown result.

A machine-learning model follows the same general process, although it uses mathematical calculations and can examine far more data.

Data Quality Matters

A model can only learn from the information it receives.

If the training dataset is too small, inaccurate, incomplete, or unrepresentative, the model may learn unreliable patterns. For example, a student-performance model trained using data from only one school may not work equally well in schools with different teaching methods or grading systems.

Bias in the data can also lead to biased predictions. When certain groups or situations are missing from the dataset, the model may perform poorly for those cases.

For this reason, building a machine-learning system involves more than choosing an algorithm. Developers must also collect suitable data, check it for errors, evaluate the model carefully, and monitor its performance after deployment.

Machine Learning in One Sentence

Machine learning is a way of creating systems that learn patterns from examples and use those patterns to make predictions about new data.

The process can be summarized in four stages:

  1. Collect a dataset containing examples.
  2. Identify the features and labels.
  3. Train a model to learn patterns.
  4. Use the model to make predictions about new examples.

Although real machine-learning systems can become highly complex, their foundation is simple: they learn from data instead of being manually programmed for every rule.

Mini Challenge: Create a Customer Dataset

Design a small dataset for predicting whether a customer will buy a product.

Begin by deciding which features could help make the prediction. Possible features include:

  • Customer age
  • Number of previous purchases
  • Time spent viewing the product
  • Product price
  • Discount offered
  • Whether the customer clicked an advertisement

Your label should show the final outcome:

  • Bought
  • Did not buy

Create a table with at least six customers. Include different combinations of feature values and assign an outcome to each example.

Then answer the following questions:

  1. Which columns are the features?
  2. Which column is the label?
  3. What patterns can you observe?
  4. What would you predict for a new customer?
  5. Would your dataset be large and varied enough for a real business decision?

This activity demonstrates the essential idea behind machine learning: examples from the past can be used to discover patterns and make predictions about the future.

More to read


Features, Labels, Inputs, and Outputs
16/7/2026

Can we estimate what a house will sell for? Can we tell whether a customer is likely to cancel a subscription? Can we identify a defective product before it leaves the factory?

AI, Machine Learning, Deep Learning, and Generative AI
30/6/2026

Artificial intelligence can sound like a giant robot brain hiding behind a glowing screen. People talk about AI, machine learning, deep learning, neural networks, generative AI, large language models, computer vision, and natural language processing as if they are all the same thing.

From JavaScript to TypeScript: A Practical Guide for Developers Making the Switch
30/6/2026

JavaScript is one of the most important languages in modern software development. It runs in the browser, powers backend services with Node.js and Bun, and is used everywhere from small websites to large-scale applications.

From Idea to Live Landing Page: Build a Node.js MVP and Publish It on a VPS
27/6/2026

Learn how to turn a product idea into a live Node.js landing page MVP with a subscriber form, SQLite database, admin export, VPS deployment, Caddy reverse proxy, and HTTPS.