AI/ML

What Is Machine Learning? AI, Supervised, Unsupervised and Reinforcement Learning Ep01

KaveeshaGNov 29, 2026 • 12 min read
What Is Machine Learning? AI, Supervised, Unsupervised and Reinforcement Learning Ep01
Part 1 of 18

Machine Learning: From 0 to Machine

PreviousNext

“Stop writing the rules. Show the machine the examples and let it find them.”

Every week someone tells me they want to “get into AI”, and in the same breath asks whether they need to learn deep learning, ChatGPT prompting, or calculus first. The honest answer is none of those. You need a clear picture of what machine learning actually is, where it sits inside AI, and the three very different ways a machine can learn.

That is what this first post is about. It is the foundation for an 18-part series, Machine Learning: From 0 to Machine, that starts with “what is learning?” and ends with a model you trained yourself, running on Kubernetes. Along the way we will write real Python with scikit-learn, starting today.

What AI actually means

Artificial intelligence (AI) is the broad goal of making machines do tasks that normally need human intelligence: recognising a face, understanding a sentence, planning a route, deciding the next move in a game.

There are two very different ways to get there. The first is to write the intelligence by hand: rules, decision tables, search algorithms. A chess engine from the 1990s or a fraud system full of if amount > 500000 and country != home checks is AI built this way. The second is to let the machine learn the behaviour from data. That second family is machine learning.

It also helps to separate two ambitions. Narrow AI is very good at one task (translating, detecting spam, recommending videos). General AI would handle any intellectual task a person can. Everything you use today, including the most impressive chatbots, is narrow AI; general AI is still a research goal, not a product.

Where machine learning fits

Think of it as a set of nested circles:

  • Artificial intelligence, the whole field, rule-based and learned.
  • Machine learning (ML), systems that improve at a task by learning patterns from data instead of following hand-written rules.
  • Deep learning, ML that uses neural networks with many layers. It powers image recognition, speech and modern language models.
  • Generative AI and LLMs, deep learning models that create new text, images or code: ChatGPT, Claude, Gemini.

So when someone says “AI” in 2026, they usually mean the innermost circle. This series starts from the second circle and works inward, because every idea in deep learning (loss functions, gradient descent, overfitting) is born in classic machine learning.

A classic definition from Tom Mitchell makes the idea precise: a program learns from experience E with respect to a task T and a performance measure P if its performance on T, measured by P, improves with E. For a spam filter, T is “classify email”, E is thousands of labelled emails, and P is the percentage it gets right.

Rules vs learning: flipping the equation

In traditional programming you give the computer rules and data, and it gives you answers. You have to know the rules up front and write every one of them.

Machine learning flips that. You give the computer data and the answers you already know for that data, and the training process produces the rules. Those learned rules are called the model. You then use the model on new data it has never seen.

Spam is the classic case. Writing rules (“contains free“, “has three exclamation marks”) works for a week, then spammers adapt and your rule list becomes a maintenance nightmare. Give a learning algorithm 50,000 emails already marked spam or not spam, and it finds the patterns itself, including ones you would never have thought to write. Retrain on fresh data and it adapts too.

Machine learning is not always the right tool. If you can write the rule in a few lines and it never changes (tax brackets, input validation), write the rule. ML earns its place when the rules are too many, too fuzzy, or keep changing.

The vocabulary you will see in every post

A handful of words will come up in every episode, so let’s pin them down now with one running example: predicting the price of a house.

  • Feature, an input the model looks at (size in square feet, number of bedrooms, distance to Colombo). Also called an attribute or variable; together they form the feature vector x.
  • Label, the answer we want to predict (the price, y). Only some problems have labels.
  • Model, the learned function that maps features to a prediction, ŷ = f(x).
  • Training, the process of adjusting the model’s internal numbers so its predictions match the known labels.
  • Parameters, those internal numbers the model learns (weights, coefficients). Hyperparameters are settings you choose before training (how many clusters, how deep a tree).
  • Inference, using the trained model to predict on new data.
  • Train/test split, keeping some labelled data hidden during training so you can check the model on examples it has never seen. A model that only does well on its training data has memorised, not learned.

The three ways a machine can learn

The biggest decision in any ML problem is which kind of learning it is. That depends on one question: what does your data give you?

Type 1: Supervised learning

In supervised learning every training example comes with the correct answer, the label. The model’s job is to learn the mapping from features to label so it can predict labels for new examples. It is called supervised because the labels act like a teacher marking every answer.

There are two flavours, decided by what you predict:

  • Regression when the label is a number (house price, tomorrow’s rainfall, delivery time).
  • Classification when the label is a category (spam or not, disease or healthy, cat, dog or bird).

Here is the smallest possible supervised model: learning house prices from size.

from sklearn.linear_model import LinearRegression

# Features: house size in square feet. Labels: price in millions of rupees.
sizes = [[800], [1000], [1200], [1500], [1800], [2200]]
prices = [18, 22, 26, 32, 38, 46]

model = LinearRegression()
model.fit(sizes, prices)          # learn the pattern from labelled examples

print(model.predict([[1600]]))    # price for a house the model has never seen
print(model.coef_, round(model.intercept_, 2))

Running it prints:

[34.]
[0.02] 2.0

What’s actually happening here

fit is the training step. The model searched for the straight line that best matches the six labelled examples and found price = 0.02 × size + 2.0. That 0.02 (Rs. 20,000 per square foot) and 2.0 are the learned parameters. predict is inference: a 1,600 sq ft house the model never saw comes out at Rs. 34 million.

Notice the shape of the scikit-learn API, because it never changes: create a model, call fit(X, y), call predict(X_new). Every supervised algorithm in Module 2 (linear and logistic regression, decision trees, random forests, gradient boosting, SVM, KNN, Naive Bayes and neural networks) follows this same three-step pattern.

Type 2: Unsupervised learning

In unsupervised learning there are no labels at all. You hand the algorithm raw data and ask it to find structure: groups of similar items, unusual points, or a simpler way to describe the data with fewer numbers.

The most common task is clustering. Imagine a shop with customer records but no idea what “types” of customer it has:

from sklearn.cluster import KMeans

# Each row is a customer: [visits per month, average spend in Rs. '000]
customers = [
    [2, 1.5], [3, 2.0], [2, 1.8],      # occasional, low spend
    [12, 2.5], [14, 3.0], [11, 2.2],   # frequent, low spend
    [4, 15.0], [3, 18.0], [5, 16.5],   # rare, high spend
]

kmeans = KMeans(n_clusters=3, n_init=10, random_state=42)
groups = kmeans.fit_predict(customers)   # no labels given

print(groups)
print(kmeans.cluster_centers_.round(1))

Output:

[2 2 2 0 0 0 1 1 1]
[[12.3  2.6]
 [ 4.  16.5]
 [ 2.3  1.8]]

What’s actually happening here

We never told K-means which customer belongs where; the comments in the code are for you, not the model. It discovered three groups on its own and returned a cluster number for each customer. The numbers 0, 1 and 2 are arbitrary names, so they can come out in a different order on your machine; what matters is that the three regulars, the three big spenders and the three occasional visitors each end up together. The cluster centres describe each group: about 12 visits with low spend, about 4 visits with Rs. 16,500 spend, and about 2 visits with low spend.

Giving those groups business meaning (“loyal regulars”, “big-ticket buyers”) is still your job. Unsupervised learning finds the structure; a human interprets it. Module 3 covers nine of these algorithms, from K-means and DBSCAN to PCA, t-SNE and UMAP.

Type 3: Reinforcement learning

Reinforcement learning (RL) is different from both. There is no fixed dataset. An agent takes actions in an environment, sees the new state, and receives a reward (or penalty). Over many attempts it learns a policy, a strategy for which action to take in each state, that maximises its total reward. Nobody tells it the right move; it finds out by trial and error.

This is how game-playing AI, robot navigation and part of ChatGPT’s training (RLHF) work. Here is a tiny version in plain Python: an agent in a five-square corridor that must learn to walk right to reach the goal, losing a point for every step and gaining ten at the goal.

import random

# A corridor: states 0..4, the goal is state 4. Actions: 0 = left, 1 = right.
N_STATES, GOAL = 5, 4
Q = [[0.0, 0.0] for _ in range(N_STATES)]
alpha, gamma, epsilon = 0.5, 0.9, 0.2
random.seed(0)

for episode in range(200):
    state = 0
    while state != GOAL:
        # explore sometimes, otherwise take the best known action
        if random.random() < epsilon:
            action = random.choice([0, 1])
        else:
            action = 0 if Q[state][0] > Q[state][1] else 1
        next_state = max(0, state - 1) if action == 0 else state + 1
        reward = 10 if next_state == GOAL else -1
        best_next = max(Q[next_state])
        Q[state][action] += alpha * (reward + gamma * best_next - Q[state][action])
        state = next_state

for s in range(GOAL):
    print(s, ["left", "right"][Q[s].index(max(Q[s]))], [round(q, 2) for q in Q[s]])

Output:

0 right [3.12, 4.58]
1 right [3.12, 6.2]
2 right [4.58, 8.0]
3 right [6.2, 10.0]

What’s actually happening here

The table Q stores how good each action is in each state. Every step, the agent updates one entry using the reward it just got plus the best value it expects from the next state; that one line is Q-learning, which we will unpack properly in Module 5. After 200 episodes the agent has learned “go right” in every square, and you can see the value rising as it gets closer to the goal (4.58, 6.2, 8.0, 10.0). The epsilon setting makes it explore a random move 20% of the time, so it doesn’t settle on the first path it happens to find.

Which type should you use?

Ask these questions about your problem, in order:

  1. Do you have past examples with the correct answer attached? Use supervised learning. Number to predict → regression; category → classification.
  2. Do you only have raw data and want to find groups, outliers or simpler representations? Use unsupervised learning.
  3. Is the problem a sequence of decisions, where each action changes what happens next and the payoff may come much later? Use reinforcement learning.

A few quick checks: predicting a student’s final mark from attendance is supervised regression. Grouping news articles by topic with no labels is unsupervised clustering. Teaching a robot to clean windows on buildings it has never seen is reinforcement learning. Real systems often combine them; ChatGPT, for example, is pre-trained on huge amounts of unlabelled text, then fine-tuned with labelled examples and reinforcement learning from human feedback.

The honest limitations

  • Data quality caps everything. A model can only learn patterns that exist in its data. Noisy labels, missing values or a dataset that doesn’t represent real users will produce a confident, wrong model.
  • Models find correlation, not cause. A model may learn that ice cream sales predict drownings; both rise in hot weather. Useful for prediction, dangerous for decisions.
  • Bias comes along for the ride. If historical hiring or lending data was unfair, a model trained on it will repeat that unfairness, at scale.
  • More data and compute are not free. Labelling thousands of examples costs time and money, and RL can need millions of trials, which is why it is mostly used in simulators and games.
  • Sometimes a rule is better. If the logic is simple, stable and must be explainable line by line, plain code wins.

Set up for the series

Every coding post uses the same small toolkit. Install it once:

pip install numpy pandas scikit-learn matplotlib

The examples in this series are written and tested with Python 3.13 and scikit-learn 1.9. Any recent Python 3 and scikit-learn 1.x should run them; if an output differs slightly, the version is the first thing to check.


Where we’re headed

The series runs in six modules:

  1. Foundations (this post)
  2. Supervised learning, nine algorithms, two per post, plus how to evaluate them
  3. Unsupervised learning, nine algorithms including clustering, PCA, t-SNE and UMAP
  4. Deep learning, CNNs, RNNs and LSTMs, transformers
  5. Reinforcement learning, from Q-learning to policy gradients
  6. From model to machine, serving a model with FastAPI and Docker, then running it on Kubernetes

Next up is Ep02: linear regression and logistic regression. We will take the one-line LinearRegression you just used, open it up, and build the cost function and gradient descent behind it by hand, then see how one small change, the sigmoid, turns it into a classifier.


This post is part of the CeyTech series Machine Learning: From 0 to Machine – deep tech, no fluff. Try changing the house sizes or adding a fourth customer group, and tell me what your model learned.




Share this story:

Comments (...)

You must be signed in to join the discussion.

Loading comments...