TechByteByByte

What Is Machine Learning?

Understand what machine learning is, why it exists, how training and inference work, and how the basic ML workflow connects to modern AI systems.

#Machine Learning#AI#ML Fundamentals#AI Foundations

Begin with the central question

How can software improve from examples instead of receiving a rule for every situation?

This question explains why What Is Machine Learning? deserves its own lesson. Each definition, calculation, and code example below will answer a specific part of it.

examples → learning algorithm → learned model → new prediction

Before you continue: three tools for this module

  • Example: one past case the system can learn from.
  • Pattern: a repeatable relationship found across examples.
  • Model: the learned rule represented by numbers or structure.

You do not need to memorize these yet. Return to this small map whenever a term reappears.


What You Will Understand

  • Core Vocabulary: Master the essential terminology that anchors every ML and AI discussion, including datasets, samples, features, labels, models, training, and inference.
  • Parameters vs. Hyperparameters: Learn the critical distinction between parameters (learned internally by the model) and hyperparameters (manually set by the engineer).
  • AI Component Identification: Gain the ability to dissect any real-world AI system—from spam filters to large language models—and accurately map its underlying ML components.

Start with the central shift:

Traditional software: human writes rules + data → answers
Machine learning:     examples + known answers → learned model
                                             learned model + new data → prediction

The model does not receive human-like understanding. Training adjusts numbers inside it until its outputs fit useful patterns in the examples.


Why Machine Learning Exists

Traditional programming

You write explicit rules, the computer follows them exactly.

# Build a small, inspectable example of What Is Machine Learning.
# Follow the data, learned values, predictions, and evaluation in order.
def is_spam(email):
    if "win a free prize" in email.lower():
        return True
    return False

This works until the problem is too complex, too fuzzy, or changes too often for you to hand-write every rule. Spam email phrasing evolves constantly. Nobody can hand-write a rule for “does this image contain a cat” or “is this sentence toxic.”

Machine learning

Instead of writing the rules yourself, you show the computer many examples of inputs and correct outputs, and let it figure out the rules itself.

Traditional programming:  Rules + Data  →  Program  →  Output
Machine learning:         Data + Output →  Program (learns the rules)

That flipped relationship — the program is now an output of a process, not something you hand-wrote — is the entire reason ML exists.


Teaching with Examples Instead of a Rulebook

Imagine teaching a child to recognize dogs. You don’t hand them a 200-page rulebook of “a dog has four legs, fur, a snout of length X…” — you show them hundreds of photos labeled “dog” and “not dog,” and their brain gradually works out the pattern itself. That gradual, example-driven pattern-extraction is exactly what ML does, just with math instead of a brain.


4. Core Concept

Here is the vocabulary, defined precisely, once — after this you can use these terms freely for the rest of the course.

TermDefinition
DatasetThe full collection of examples used to teach or test a model
Sample / ExampleOne single data point in the dataset (one email, one image, one row)
FeatureA measurable input property used to make a prediction (e.g., email length, word count)
LabelThe correct answer for a given example (e.g., “spam” or “not spam”) — only present in supervised data (Module 2)
ModelThe mathematical structure that learns patterns from data and makes predictions
TrainingThe process of adjusting a model’s internal numbers so its predictions get closer to the correct labels
InferenceUsing an already-trained model to make a prediction on new, unseen input
ParametersThe internal numbers the model learns automatically during training (e.g., weights in a linear equation)
HyperparametersSettings you choose before training that control how training happens (e.g., learning rate, number of trees)

A concrete example

Predicting house prices from square footage:

Square footage (feature)Price (label)
1000$200,000
1500$290,000
2000$400,000

A model might learn: price ≈ 190 × square_footage + 15000

  • 190 and 15000 are parameters — the model learned these values from the data.
  • “How many training passes to run” or “how fast to adjust these numbers” are hyperparameters — you set these before training starts.

5. How It Works — Step by Step

1. Collect data           →  gather examples (features + labels)
2. Split data              →  training set / validation set / test set (Module 4)
3. Choose a model type      →  linear regression, decision tree, neural network...
4. Train                   →  model adjusts its parameters to fit the training data
5. Evaluate                →  check performance on data it hasn't seen
6. Tune                    →  adjust hyperparameters, retrain if needed
7. Deploy                  →  use the trained model for real predictions (inference)
8. Monitor                 →  watch performance in production, retrain when it degrades

🧠 Training vs. inference, precisely:

  • Training = the model is changing — parameters are being adjusted based on labeled examples. Computationally expensive, done occasionally (once, periodically, or continuously).
  • Inference = the model is fixed — you’re just running input through it to get a prediction. Cheap(er), done constantly, in real time.

Every time you send a message to an LLM, that’s inference. The model’s parameters (its “weights”) were fixed during a separate, earlier, extremely expensive training process.


6. Mathematical Intuition

Read the mathematics as a story

examples → learning algorithm → learned model → new prediction

First identify the input, the operation, and the output. Then read the symbols as a shorter way to describe that same journey; do not begin by memorizing the formula.

You don’t need heavy math for this module — just the shape of what a model actually is.

A very simple model (linear regression, covered fully in Module 7) is literally an equation:

prediction = (weight × feature) + bias
  • weight and bias are the parameters.
  • “Training” means: repeatedly nudge weight and bias so that prediction gets closer to the real label, across all training examples, using a loss function (Module 13) to measure how wrong the current prediction is.

That’s genuinely the whole idea, even for far more complex models (neural networks, LLMs): lots more parameters, lots more math, same core loop — measure how wrong you are, adjust parameters to be less wrong, repeat.


7. Small Worked Example

Walk through the example

  1. Identify what each input number represents.
  2. Follow one operation at a time and keep the units or class meanings attached.
  3. Translate the result back into an ordinary sentence about the original problem.

The goal is not merely to obtain the answer; it is to expose the model’s decision process.

By hand, no code — predicting a test score from hours studied:

Hours studied (feature)Test score (label)
150
260
370
480

Just by looking at this, you (a human “model”) can infer the pattern: score ≈ 40 + 10 × hours. If someone studies for 5 hours, you’d predict 90. That mental leap — from labeled examples to a general rule you can apply to new, unseen input — is machine learning, done in your head instead of by an algorithm.


8. Python Example

What the code will demonstrate

The following What Is Machine Learning? code turns the worked example into an experiment you can repeat. First predict the result; then prepare the small dataset, apply the technique, inspect the important intermediate values, and compare the actual output with your prediction.

Python and library symbols used below

  • NumPy (np) stores and calculates with numeric arrays.
  • pandas (pd) represents table-shaped data when it is used.
  • scikit-learn provides tested implementations with a consistent .fit(...) and .predict(...) workflow.
# Build a small, inspectable example of What Is Machine Learning.
# Follow the data, learned values, predictions, and evaluation in order.
import numpy as np
from sklearn.linear_model import LinearRegression

# Training data: hours studied (feature) -> test score (label)
hours_studied = np.array([[1], [2], [3], [4]])   # features must be 2D for sklearn
test_scores = np.array([50, 60, 70, 80])          # labels

# 1. Choose a model
model = LinearRegression()

# 2. Train (the model learns its parameters from the data)
model.fit(hours_studied, test_scores)

# 3. Inspect the learned parameters
print("Learned weight:", model.coef_)       # how much score increases per hour
print("Learned bias:", model.intercept_)    # baseline score at 0 hours

# 4. Inference — predict on NEW, unseen input
new_hours = np.array([[5]])
predicted_score = model.predict(new_hours)
print("Predicted score for 5 hours:", predicted_score)

Expected Output (approximate):

Learned weight: [10.]
Learned bias: 40.00000000000006
Predicted score for 5 hours: [90.]

How It Works

  • model.fit(...) is training — it’s where LinearRegression computes the weight and bias parameters that best fit the data.
  • model.predict(...) is inference — the model is now fixed, and we’re just running a new input (5 hours) through the equation it learned.
  • Notice the model correctly reconstructed the exact pattern we set up by hand in Section 7 (40 + 10 × hours) — this is sklearn doing, with real optimization math, precisely what you did intuitively by eye.

9. Real-World Example

An e-commerce company wants to predict whether a customer will return a purchased item.

  • Dataset: millions of past orders
  • Features: item price, item category, customer’s past return rate, time between order and typical return window, shipping method
  • Label: did this specific order actually get returned? (yes/no)
  • Model: trained on historical orders where the outcome is already known
  • Inference: for every new order coming in today, the trained model predicts a return probability in real time — used to, say, flag high-risk orders for a different packaging process

10. How This Is Used in AI

From mechanism to product

Machine learning turns examples into a reusable prediction rule. In an LLM, this learning happened before the chat; the application normally uses the already-trained model.

How this connects to LLMs

request → data or context preparation → model computation → evaluated output

An LLM may use this idea during training, or an AI application may use a separate ML component around the LLM. Those are different locations in the system, and the explanation below identifies which one applies.

🤖 How Is This Used in AI?

ML ConceptWhere it shows up in AI systems
DatasetThe (enormous) text corpus an LLM is trained on; a RAG system’s document collection
FeaturesFor LLMs, the input tokens themselves; for a reranker, query-document match signals
LabelsFor classic supervised fine-tuning, human-written “correct” responses; for base LLM training, “the next actual word” (Module 2 explains this in depth)
TrainingPretraining and fine-tuning an LLM; also training a small classifier (e.g., intent detection)
InferenceEvery single time you send a prompt to an LLM and get a response back
ParametersAn LLM’s weights — literally billions of numbers, learned the same way our tiny weight/bias example learned two numbers
HyperparametersLearning rate and batch size during LLM training; also things like temperature at inference time (a different, prediction-time setting, not a training hyperparameter — worth not conflating the two)

11. How This Is Used in Agentic AI

Trace one agent step

goal + state → model proposes → runtime validates → tool or response → evaluation

The model produces a prediction or proposal. The agent runtime is ordinary software that manages tools, permissions, state, retries, and execution; it may use this ML concept directly, indirectly through an LLM, or not at all.

🤖 An agent’s core loop often includes small ML-style components sitting alongside the LLM itself:

  • A lightweight classifier deciding which tool to call (Module 8)
  • A reranking model deciding which retrieved document is most useful (Modules 9, 18)
  • An evaluation model or metric scoring whether the agent’s final answer was good (Module 17)

Understanding “dataset → model → training → inference” means you can recognize when a piece of an agent pipeline actually is a small ML model, versus when it’s the LLM itself reasoning in natural language — an important architectural distinction when designing or debugging an agent system.


12. Common Beginner Mistakes

⚠️ Mistake

Incorrect idea: Confusing parameters and hyperparameters

Why it is incorrect: Parameters are learned by the model during training (you never set them directly). Hyperparameters are chosen by you, before training starts. If you find yourself manually setting a “weight,” you’re either misunderstanding the model or working with a hyperparameter, not a true learned parameter.

⚠️ Mistake

Incorrect idea: Thinking training and inference are the same computational cost

Why it is incorrect: Training an LLM can cost millions of dollars and take weeks on huge GPU clusters. Inference (answering one prompt) takes a fraction of a second and a tiny fraction of the resources. This cost asymmetry is why companies can offer LLM API access cheaply, even though training that same model was enormously expensive.

⚠️ Mistake

Incorrect idea: Assuming ML always needs labels

Why it is incorrect: Only supervised learning strictly needs labels. Module 2 covers unsupervised, self-supervised, and reinforcement learning — all valid ML, none of them requiring hand-labeled data in the traditional sense.


13. Important Distinctions

TrainingInference
Model parameters are being adjustedModel parameters are fixed
Computationally expensive, infrequentCheap(er), happens constantly
Needs (usually large) datasetsNeeds just one input at a time
Produces a trained modelProduces a prediction/output
ParametersHyperparameters
Learned automatically from dataChosen by a human before training
Example: weights, biasExample: learning rate, number of trees, epochs
Different every time you retrain (usually)You control these directly

14. When Should You Use This?

Use ML (instead of hand-written rules) when:

  • The pattern is too complex or subtle to describe with explicit rules
  • You have (or can obtain) representative examples of the pattern
  • The pattern may change over time and you want the system to adapt by retraining, not by rewriting code
  • “Approximately right, most of the time” is an acceptable trade-off for the problem (ML is inherently probabilistic, not exact)

15. When Should You NOT Use This?

Don’t reach for ML when:

  • A simple, explicit rule genuinely covers the case reliably (e.g., “is this email address syntactically valid” — just use a regex)
  • You need guaranteed, 100% deterministic, explainable behavior (e.g., tax calculation logic) — an ML model’s behavior is a probabilistic approximation, not a guarantee
  • You don’t have and can’t obtain any representative data — ML has nothing to learn from
  • The cost of building/maintaining a training pipeline outweighs simply writing (and maintaining) the rules by hand for a small, stable problem

16. Production Considerations

  • Data quality — a model is only as good as what it was trained on; this matters more than almost anything else in this module (elaborated fully in Module 3).
  • Monitoring — a model’s real-world performance can quietly degrade over time as the world changes (data drift — Module 21); production systems need to watch for this, not assume training-time performance holds forever.
  • Retraining — decide upfront how and when a model gets retrained as new data arrives.
  • Inference cost at scale — a model cheap to run once can become expensive when called millions of times a day; this is a real engineering constraint, not just a training-time concern.

17. AI Engineer Takeaway

🎯 AI Engineer Takeaway: Machine learning is the shift from hand-writing rules to learning rules from examples. Every ML and AI system you’ll ever work with — from a simple spam filter to a 100-billion-parameter LLM — is built from exactly the same five moving pieces: data, a model, training, parameters, and inference.

Once these are second nature, every more advanced concept in this course is just a variation or elaboration of this same basic loop.


18. Interview Questions

Basic Questions

Q: What is machine learning, in your own words?

A: A strong answer: A strong answer: “Machine learning is a way of building software where, instead of a programmer writing explicit rules, the program learns patterns automatically from example data. You give it inputs and (in the supervised case) correct outputs, and a training process adjusts the model’s internal parameters until its predictions match the examples well — and, ideally, generalize to new, unseen inputs too.”

Q: What is the difference between training and inference?

A: Training is the (often expensive, infrequent) process of adjusting a model’s parameters using data. Inference is using the already-trained, now-fixed model to make a prediction on new input — cheap, fast, and done repeatedly in production. A helpful example: training an LLM might take weeks on thousands of GPUs; answering one user’s prompt (inference) takes under a second on comparatively modest hardware.

Q: What’s the difference between a parameter and a hyperparameter?

A: Parameters are learned automatically by the model during training (e.g., the weights in a linear regression). Hyperparameters are chosen by the engineer before training starts and control how training happens (e.g., learning rate, number of trees in a forest, number of training epochs). A useful test: if you’re setting it in code before calling .fit(), it’s a hyperparameter; if the model computed it, it’s a parameter.

Intermediate Questions

Q: Why can’t traditional rule-based programming solve every problem ML solves?

A: Because many real-world patterns are too complex, too fuzzy, or too context-dependent for a human to enumerate as explicit rules — think “does this image contain a cat” or “is this sentence sarcastic.” ML sidesteps needing an explicit rulebook by learning statistical patterns directly from labeled examples, which scales to problems no reasonable amount of hand-written logic could cover.

Q: If a company wants to build a spam filter, what would the dataset, features, and labels look like?

A: Dataset: a large collection of past emails. Features: measurable properties of each email — sender reputation, presence of certain phrases, number of links, capitalization ratio, etc. Labels: whether that historical email was actually spam or not (from user reports or manual review). The model learns, from this labeled history, a general pattern it can apply to brand-new incoming emails at inference time.

Scenario-Based Questions

Q: Your team says: “We don’t need ML for this — we’ll just write rules for spam detection.” Under what conditions might that actually be the right call, and when would it break down?

A: Thought process: Start by identifying what makes a problem rule-friendly versus ML-friendly.

Investigation: Rule-based spam detection can work reasonably well early on, when spam patterns are simple and consistent (e.g., “contains the phrase ‘free money’”). It breaks down as spammers actively adapt to evade known rules, as the volume/variety of spam patterns grows beyond what’s practical to hand-enumerate, and as the cost of manually maintaining an ever-growing rule list outpaces the value it delivers.

Correct answer: Rules are a reasonable, low-cost starting point for a narrow, stable, well-understood problem. ML becomes the better choice once the pattern space is large, adversarial (attackers actively adapt), or constantly evolving — exactly spam detection’s real-world profile over time.

Production consideration: Many real systems actually use both: fast, cheap, explainable rules to catch obvious cases immediately, backed by an ML model to catch the subtler, evolving cases rules miss — a hybrid approach rather than an all-or-nothing choice.


Next: Module 02 — Types of Machine Learning — supervised, unsupervised, self-supervised, and reinforcement learning, and why modern LLMs are built almost entirely on self-supervised learning.

Author
TechByteByByte Editorial Team
Reviewed by
TechByteByByte Admin
Published
Last reviewed