Types of Machine Learning

Machine Learning Fundamentals with Python

3 min read

Published Nov 16 2025


10
0
0
0

ClusteringImagesK-MeansLinear RegressionLogistic RegressionMachine LearningNeural NetworksNLPNumPyPythonRandom Forestsscikit-learnSupervised LearningUnsupervised Learning

Machine Learning methods can be broadly grouped into three main types: Supervised, Unsupervised, and Reinforcement learning.

Each category is based on the type of data we have and the goal we’re trying to achieve.




Supervised Learning

Idea:
We already know the correct answers (labels) for our data. The model’s job is to learn the relationship between inputs (features) and outputs (labels). In other words, the model is supervised by example answers.


Common tasks:

  • Regression: Predict continuous values, e.g. house prices, temperatures
  • Classification: Predict discrete categories, e.g. spam or not spam, dog vs cat

Python example

Simulate a very small example with Scikit-learn to show how supervised learning works:

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

# Sample dataset: 1 = spam, 0 = not spam
# Features: [num_links, contains_offer_word, email_length]
X = [
    [5, 1, 100],
    [0, 0, 300],
    [2, 1, 150],
    [0, 0, 250],
    [3, 1, 120]
]
# Labels
y = [1, 0, 1, 0, 1]

# Split into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=42)

# Train a logistic regression model
model = LogisticRegression()
model.fit(X_train, y_train)

# Predict on test data
predictions = model.predict(X_test)

print("Predictions:", predictions)
print("Actual:", y_test)
print("Accuracy:", accuracy_score(y_test, predictions))

Explanation:

  • We have labeled data (spam or not spam).
  • The model learns patterns (e.g., more links or “offer” keywords = spam).
  • Then we test how well it performs on unseen data.
  • Predictions - What the model thinks the labels should be based on patterns it learned during training.
  • Actual - The real, correct labels that come from your original dataset, NOT from the model.
  • Accuracy - What fraction of the predictions the model got right, (1 is 100% correct, 0,5 is 50% correct, 0 is 0% correct etc.)

This is supervised learning because the correct answers were known during training.






Unsupervised Learning

Idea:
Here, we don’t have labels. The goal is to find patterns, structure, or groupings on our own.


Common tasks:

  • Clustering: Grouping similar items together, e.g. customer segmentation
  • Dimensionality reduction: Simplifying complex data, e.g. compressing features for visualisation

Python example

Clustering customers by spending behaviour using KMeans to automatically group customers based on spending habits.

from sklearn.cluster import KMeans
import numpy as np

# Sample data: [annual_income, spending_score]
X = np.array([
    [15, 39],
    [16, 81],
    [17, 6],
    [18, 77],
    [19, 40],
    [20, 76],
    [21, 10],
    [22, 94]
])

# Create a KMeans model with 2 clusters
kmeans = KMeans(n_clusters=2, random_state=0)
kmeans.fit(X)

# Cluster assignments
print("Cluster labels:", kmeans.labels_)

# Cluster centers
print("Cluster centers:\n", kmeans.cluster_centers_)

Explanation:

  • We had no labels, the algorithm automatically grouped the data into clusters.
  • Each cluster might represent a type of customer, e.g. “low spenders” vs “high spenders”.
  • This is unsupervised learning, the model discovered structure without supervision.
  • The cluster labels is assigning the data in to two groups of 0 or 1.
  • The cluster centres are the centroids of the clusters, eg. [18.0, 23.75] represent customers with income ≈ 18 and low spending score ≈ 24.
  • So the two groups are:
    • Group 1: Low Spenders - These might be customers with modest spending habits.
      • Income range: 15–21
      • Spending score: 6–40
      • Centered around: (~18, ~24)
    • Group 2: High Spenders - These are the high-spending customers.
      • Income range: 16–22
      • Spending score: 76–94
      • Centered around: (~19, ~82)





Reinforcement Learning

Idea:
The model (called an agent) learns by interacting with an environment. It takes actions, receives rewards or penalties, and learns which actions lead to the best outcomes.


Common applications:

  • Game playing, e.g. AlphaGo, chess engines
  • Robotics and autonomous driving
  • Dynamic decision-making, e.g. trading bots

We won't show python example of a full reinforcement learning demo here (it usually needs simulations), but here’s the intuition:

Agent → takes action → Environment → gives reward → Agent updates strategy

Example:

  • The agent is a robot learning to walk.
  • Each step forward = reward (+1), falling down = penalty (–10).
  • Over time, it learns which movements lead to higher total rewards.





Summary

Learning Type

Has Labels?

Goal

Example

Supervised

Yes

Learn mapping from inputs → outputs

Predict house prices

Unsupervised

No

Find structure or patterns

Cluster customers

Reinforcement

No - but gets rewards

Learn actions that maximize long-term reward

Train an AI to play a game


Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact