Machine Learning
Course
Dr. Mohamed-Rafik Bouguelia
mohamed-rafik.bouguelia@hh.se
Halmstad University, Sweden.
You can also watch the video corresponding to
this lecture at: https://youtu.be/JEn0ZZwaPqo
About this Course
Supervised ML
ML Algo. Labeled Expert • Linear and nonlinear regression
and classification methods,
(learner) data (teacher) including:
Logistic Regression
SVMs
Random Forest
Neural Networks
Deep NN (CNN, RNN, LSTM …)
… and many more.
• Evaluate their performance.
• Achieve a good generalization.
• Use them in real-world use cases.
Data
About this Course
Supervised ML Unsupervised ML
• Clustering
– k-means, GMM, DBSCAN
– Hierarchical clustering
… etc.
• Anomaly detection.
– Density estimation, etc.
• Dimensionality reduction
ML (learner) Data – PCA, etc.
• Representation learning
– Auto-encoders, etc.
About this Course
Supervised ML Unsupervised ML Reinforcement Learning
action
• How an agent can learn to
perform a task by interacting
Learn a POLICY : with the environment?
𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎 = 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃(𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠)
• Basic RL methods such as:
– Q-learning
– Deep-Q-Networks.
AGENT ENVIRONMENT
reward,
state
About this Course
Supervised ML Unsupervised ML Reinforcement Learning
Semi-Supervised Learning
Expert
(teacher) • Observations
Few labeled
– Labeling is costly and time
data consuming (requires a lot of
ML Algo. expert effort).
(learner)
– Unlabeled data can be
collected cheaply.
• Semi-supervised methods
learn using both labeled and
unlabeled data.
Data
Large amount of
unlabeled data
About this Course
Supervised ML Unsupervised ML Reinforcement Learning
Semi-Supervised Learning
Interactive / Active Learning
• Interaction between the
algorithm and the expert during
the learning process.
Unlabeled ML Algo. Expert
data (learner) Query (teacher) • Active learning for
classification
– The algorithm selects which
data is most informative to
label (by the expert).
• Interactive anomaly
detection
Feedback – Learning to detect anomalies
that are more relevant to the
expert.
About this Course
Supervised ML Unsupervised ML Reinforcement Learning
Semi-Supervised Learning
Interactive / Active Learning
ML for Streaming / Time-Dependent Data • Data that becomes available
over time (e.g. sensors data,
video stream, market prices, …).
Sensors values
• Clustering data streams.
• Anomaly detection in
multivariate time series data.
• Online classification.
Time
About this Course
Supervised ML Unsupervised ML Reinforcement Learning
Semi-Supervised Learning
Practical Lab
Interactive / Active Learning
Assignments
ML for Streaming / Time-Dependent Data
• Guided labs that helps you better understand the concepts
studied in the lectures.
and
• Practical exercises to put your knowledge to practice and
solve real-word problems.
Know the Teacher
• Mohamed-Rafik BOUGUELIA
(short name: Rafik).
• Associate Professor in Machine Learning.
• Halmstad University, Sweden.
– Department of Intelligent Systems and Digital Design (ISDD).
– Center for Applied Intelligent Systems Research (CAISR).
• My research topics include: • Assistant Professor at Halmstad
University, Sweden.
– Joint human-machine learning.
– Anomaly and fault detection. • PhD in ML from the University
– Predictive maintenance of machines. of Lorraine, France.
– Big data and data-stream mining.
• MSc in CS from the USTHB
University, Algeria.
Introduction
Machine Learning Course.
Dr. Mohamed-Rafik Bouguelia.
mohamed-rafik.bouguelia@hh.se
What is Machine Learning?
• A subfield of artificial intelligence (AI) that gives machines the ability
to learn and improve from experience.
Machine Artificial Computer
Mathematics Statistics Learning Intelligence Science
• Instead of explicitly programming a machine to perform a task, we
program it to learn how to perform the task.
What is Machine Learning?
• A program is said to learn from experience E with respect to some task T and
performance measure P if its performance on T, as measured by P, improves with
experience E.
Suppose that Twitter
watches which Tweets you
do or do not mark as
“uninteresting”, and based
on that learns how to
better filter Tweets for you.
What is the experience E,
task T, and performance
measure P?
1. Classifying Tweets as interesting or uninteresting.
2. Watching you label Tweets as interesting or uninteresting.
3. The fraction of Tweets correctly classified as interesting / uninteresting.
What is Machine Learning?
• Usual programming
Data
Computer Output
Program
• (Supervised) Machine Learning
Data Training
Training dataset
Computer ML model (Learning)
(Data + Output)
Output
New Data model Output Predicting
• Machine learning algorithms build a model from the training data, then uses this model to
make predictions or take decisions.
What is Machine Learning?
Example:
The data consist of
images …
The output consists of
labels (Cat, Dog or Lion)
• (Supervised) Machine learning
Data Training
Computer ML model (Learning)
Output
New Data model Output Predicting
Dog (predicted label)
Cat 5%, Dog 65%, lion 30%
Example (self-driving car)
Consider the following problem:
• You have a camera on your car that
periodically captures images of the road
and send them to your app.
• You want your app to recognize what
each image contains (pedestrians, bikes,
other cars, etc.)
Why do we need machine learning:
• It is extremely hard to solve this
without machine learning.
• We can not manually define/code
general rules that allow us to recognize
what an image contains.
• Semi-supervised learning
• Interactive / active learning
Unsupervised: Supervised:
Training data does not include outputs. Training data includes desired outputs.
Clustering Anomaly detection Regression Classification
Introduction to Supervised ML:
Regression
Machine Learning Course.
Dr. Mohamed-Rafik Bouguelia.
mohamed-rafik.bouguelia@hh.se
What is Regression?
• Housing price prediction (regression)
What is Regression?
• Housing price prediction (regression)
• Suppose that you want to sell a house of size 750 feet² and want to know
how much you can get for this house, i.e. predict its price.
• How can a learning algorithm help you?
750
What is Regression?
• Housing price prediction (regression)
• you can fit a straight line to the data, and predict the price of the house.
150
750
What is Regression?
• Housing price prediction (regression)
• you can fit a straight line to the data, and predict the price of the house.
• or maybe its better to fit a quadratic function (2nd order polynomial).
750
What is Regression?
• Housing price prediction (regression)
• you can fit a straight line to the data, and predict the price of the house.
• or maybe its better to fit a quadratic function (2nd order polynomial).
How to decide
which model to
choose for this
dataset ?
We will see this
later in the
course when we
talk about model
selection …
What is Regression?
• Housing price prediction (regression)
This is an example of a supervised learning algorithm:
The right answers (here, the prices) are given in the training dataset.
More specifically, this example was a regression problem:
Predicting a continuous valued output (price).
Continuous
values
What is Regression?
More regression examples
Introduction to Supervised ML:
Classification
Machine Learning Course.
Dr. Mohamed-Rafik Bouguelia.
mohamed-rafik.bouguelia@hh.se
What is Classification?
• Breast cancer malignant/benign (classification)
(feature 1)
We only have discrete output values (in this example: 1 or 0)
What is Classification?
• Breast cancer malignant/benign (classification)
We don’t need the second axis if we simply visualize the
classes with different colors or shapes.
Two
axis
(feature 1)
Malignant ?
Only
one
axis
(feature 1)
What is Classification?
• Breast cancer malignant/benign (classification)
– The patients data can be characterized by more than one feature
• e.g.Tumor size and Age …
Malignant ?
(feature 2)
(feature 1)
What is Classification?
• Breast cancer malignant/benign (classification)
– Suppose that you get a new patient who has some tumor size s and age a, and you want
to predict if it is malignant or benign. How can a learning algorithm help you?
Malignant ?
a ?
(feature 2)
s
(feature 1)
What is Classification?
• Breast cancer malignant/benign (classification)
– you can fit a linear model to the training data, then predict the class of the new patient.
Malignant ?
a ?
So for patient (s, a),
(feature 2) we would predict the
class “benign”.
s
(feature 1)
What is Classification?
• Breast cancer malignant/benign (classification)
– you can fit a linear model to the training data, then predict the class of the new patient
– or you can fit a non-linear model to the training data …
Malignant ?
a ?
So for patient (s, a),
(feature 2) we would predict the
class “benign”.
s
(feature 1)
What is Classification?
• Breast cancer malignant/benign (classification)
Again, this is an example of a supervised learning
algorithm:
The right answers (here, the classes malignant /
benign) are given with the training dataset.
i.e. for each patient (data-point) in the training
dataset, we know if he is has a malignant or benign
cancer.
However, this example was a classification problem:
Predicting a discrete valued output (malignant /
benign).
Note: In this example we had two features (age, size), but we will see ML
algorithms that can easily deal with a much larger number of features …
What is Classification?
More classification examples • Classification is about learning
decision boundaries, and predicting
the “class” of new data-point.
speed
In 3-dimensions, this linear model is a “plan”.
In more than 3-dimensions, it’s a “hyperplan”.
size
Introduction to Supervised ML:
Regression vs. Classification
Machine Learning Course.
Dr. Mohamed-Rafik Bouguelia.
mohamed-rafik.bouguelia@hh.se
Difference between Regression and Classification
Regression:
• The output (i.e. target variable) is continuous. It consist of
real values.
output
– predicting the price of houses (in SEK)
– predicting the power consumption (in kW)
– predicting how much healthy is the patient (e.g. ∈ [0, 1])
– etc.
feature 1
Classification:
• The output (i.e. target variable) is discrete. It consists of
feature 2
classes (or categories). class A
– predicting if an image contains a cat or a dog class B
– predicting customer categories
– good/bad, healthy/sick, red/green/blue, A/B/C/D, 0/1/2
…
– etc. feature 1
Difference between Regression and Classification
Would you treat the following as a classification or as a regression problem?
• Problem 1: Amazon wants to predict how many articles will be sold over
the next 2 months.
• Problem 2:Volvo wants to detect whether the air pressure system of a
vehicle (bus) is faulty or healthy, based on data collected from similar
vehicles (know to be faulty or healthy).
• Problem 3:You want to predict the price of Bitcoin by tomorrow, based
on recent historical prices (as well as other features, e.g. news, user’s
sentiments …).
• Problem 4:You have a large set of research articles downloaded from the
Internet.You don’t know what is the topic of each article, so you want to
group them into groups of articles that talk about similar topics.
Difference between Regression and Classification
Would you treat the following as a classification or as a regression problem?
Regression • Problem 1: Amazon wants to predict how many articles will be sold over
the next 2 months.
Classification • Problem 2:Volvo wants to detect whether the air pressure system of a
vehicle (bus) is faulty or healthy, based on data collected from similar
vehicles (know to be faulty or healthy).
Regression • Problem 3:You want to predict the price of Bitcoin by tomorrow, based
on recent historical prices (as well as other features, e.g. news, user’s
sentiments …).
Clustering • Problem 4:You have a large set of research articles downloaded from the
Internet.You don’t know what is the topic of each article, so you want to
group them into groups of articles that talk about similar topics.
Introduction to Unsupervised ML:
Clustering
Machine Learning Course.
Dr. Mohamed-Rafik Bouguelia.
mohamed-rafik.bouguelia@hh.se
Introduction to Unsupervised Learning
In supervised learning (e.g. classification) we have a labeled training dataset:
So, for each data-point ∈ 𝑅𝑅 2 , we have the corresponding class-label ∈
Introduction to Unsupervised Learning
In unsupervised learning (e.g. clustering) we have an unlabeled training dataset:
In clustering, we want to explore the data
2
We only have data-points ∈ 𝑅𝑅 to find some intrinsic groups (clusters) in
it. The clusters are not known beforehand.
Some applications of clustering
Automatically
grouping together the
stories (news articles
on the Web) that talk
about the same topic.
More applications of clustering
• Grouping people based on their genes:
– DNS Microarray data: colors here corresponds to
how much individuals do or do not have a certain
gene.
– Run a clustering algorithm to group individuals into
different groups/types of people.
• Social network analysis: