Amity Institute of Information Technology
CSIT737 - Machine Learning using Python
Module 1 - Basics
Introduction to Machine Learning, Different forms of Learning;
Basics of Probability Theory, Linear Algebra and Optimization,
Overview of Target Function representations, Types of ML
techniques, Hypothesis selection through cross validation.
Dr. Partha Sarathi Chakraborty
Amity University Uttar Pradesh Noida
1
Amity Institute of Information Technology
Current Scenario
2
Amity Institute of Information Technology
Development Timeline
3
Amity Institute of Information Technology
Introduction to Machine Learning
What is
Machine See this is a keyboard.
Learning?
See one more keyboard.
Now, Identify What is this object?
Before
answering
it, look into
Human can learn from past experience few items.
and make decision of its own
4
Amity Institute of Information Technology
Hi Mogli!
What is this
Object?
As he is human being. He
can observe and learn.
5
Amity Institute of Information Technology
Machine follow instruction. It performs operations
such as arithmetic operation.
Training
through Data
dog dog cat cat
6
Amity Institute of Information Technology
Dataset
This what we called as Data
or Training dataset
So, we first need to provide
training dataset to the
machine
7
Amity Institute of Information Technology
Dataset
Common definition: Machine Learning is the study of computer algorithms that improve
automatically through experience 8
Amity Institute of Information Technology
Common definition: Machine Learning is the study of computer algorithms that improve
automatically through experience
9
Amity Institute of Information Technology
What is Machine Learning?
Machine learning (ML)† is a branch of artificial intelligence
(AI) focused on enabling computers and machines to imitate What is
the way that humans learn, to perform tasks autonomously, Machine
and to improve their performance and accuracy through Learning?
experience and exposure to more data.
†Source: [Link]
10
Amity Institute of Information Technology
Improve on task T, with respect to performance
metric P, based on experience E
11
Amity Institute of Information Technology
Traditional vs ML Approach
12
Amity Institute of Information Technology
Machine Learning
13
Amity Institute of Information Technology
Relate It!
No, more like gardening
• Seeds = Algorithms
• Nutrients = Data
• Gardener = You
• Plants = Model (Program)
14
Amity Institute of Information Technology
Why Machine Learning?
• Explosive growth of data.
• Infeasibility of manual programming for
complex tasks.
• Applications in (not limited):
– Speech & image recognition
– Fraud detection
– Recommendation systems
– Autonomous vehicles
15
Amity Institute of Information Technology
Why Machine Learning?
16
Amity Institute of Information Technology
When?
17
Amity Institute of Information Technology
Who?
18
Amity Institute of Information Technology
Learning from Examples
19
Amity Institute of Information Technology
Machine Learning Workflow
20
Amity Institute of Information Technology
Machine Learning Workflow
21
Amity Institute of Information Technology
Different forms of Learning
• Supervised (inductive) learning
– Training data includes desired outputs
• Unsupervised learning
– Training data does not include desired outputs
• Semi-supervised learning
– Training data includes a few desired outputs
• Reinforcement learning
– Rewards from sequence of actions
• Evolutionary Learning
– Biological evolution can be seen as learning process.
22
Amity Institute of Information Technology
23
Amity Institute of Information Technology
Supervised Learning
• Decision tree induction
• Evaluation of classifiers
• Naïve Bayesian classification
• Naïve Bayes for text classification
• Support vector machines
• Linear regression and gradient descent
• Neural networks
• K-nearest neighbor
• Ensemble methods
24
Amity Institute of Information Technology
An application of supervised learning
• Endless applications of supervised learning.
• An emergency room in a hospital measures 17
variables (e.g., blood pressure, heart rate, etc) of newly
admitted patients.
• A decision is needed: whether to put a new patient in
an intensive-care unit (ICU).
– Due to the high cost of ICU, those patients who may survive
less than a month are given higher priority.
• Problem: to predict high-risk patients and discriminate
them from low-risk patients.
25
Amity Institute of Information Technology
Another application
• A credit card company receives thousands of
applications for new cards. Each application
contains information about an applicant,
– age
– annual salary
– outstanding debts
– credit rating
– etc.
• Problem: Decide whether an application should
approved, i.e., classify applications into two
categories, approved and not approved.
26
Amity Institute of Information Technology
Supervised machine learning
• We humans learn from past experiences.
• A computer does not “experience.”
– A computer system learns from data, which represents “past
experiences” in an application domain.
• Our focus: learn a target function that can be used to
predict the values (labels) of a discrete class attribute,
e.g.,
– high-risk or low risk and approved or not-approved.
• The task is commonly called: supervised learning,
classification, or inductive learning.
27
Amity Institute of Information Technology
The Data and the Goal
• Data: A set of data records (also called
examples, instances, or cases) described by
– k data attributes: A1, A2, … Ak.
– One class attribute: a set of pre-defined class labels
– In other words, each record/example is labelled with
a class label.
• Goal: To learn a classification model from the
data that can be used to predict the classes of
new (future or test) instances/cases.
28
Amity Institute of Information Technology
An example: data (loan application)
Approved or not
29
Amity Institute of Information Technology
An example: the learning task
Sub-tasks:
• Learn a classification model from the data
• Use the model to classify future loan
applications into
– Yes (approved) and
– No (not approved)
• What is the class for following applicant/case?
30
Amity Institute of Information Technology
Supervised learning process: Two steps
• Learning or training: Learn a model using the
training data (with labels)
• Testing: Test the model using unseen test data
(without labels) to assess the model accuracy
Number of correct classifications
Accuracy = ,
Total number of test cases
31
Amity Institute of Information Technology
Supervised Learning
• Supervised learning: classification is
supervised learning from examples.
– Supervision: The data (observations,
measurements, etc.) are labeled with pre-defined
classes, which is
– like a “teacher” gives us the classes (supervision).
32
Amity Institute of Information Technology
Unsupervised learning
• Unsupervised learning
– Class labels of the data are not given or unknown
– Goal: Given a set of data, the task is to establish the
existence of classes or clusters in the data
• More Simply,
– There is no supervisor and only input data is available.
– The aim is now to find regularities, irregularities,
relationships, similarities and associations in the input.
33
Amity Institute of Information Technology
Unsupervised learning
• Purpose:
– Discover similarities, anomalies, or clusters in data.
• Common Techniques:
– Clustering (e.g., K-Means, DBSCAN)
– Dimensionality Reduction (e.g., PCA, t-SNE)
– Association Rules (e.g., Market Basket Analysis)
– Pattern Mining
• It is adopted as amore general term than frequent pattern mining
or association mining.
– Outlier Detection
• It is the process of finding data examples with behaviours that are
very different from the expectation (outliers or anomalies).
34
Amity Institute of Information Technology
Unsupervised learning
• Applications of Unsupervised Learning
– Domain Use Case Example
– E-commerce Customer segmentation
– Cybersecurity Anomaly detection
– Healthcare Patient risk profile grouping
– Marketing Product recommendations
– Finance Fraud detection, transaction grouping
• Advantages:
– No need for labeled data
– Can handle large-scale, unlabeled datasets
– Reveals unexpected patterns
35
Amity Institute of Information Technology
Clustering
• Clustering is a technique for finding similarity
groups in data, called clusters. I.e.,
– it groups data instances that are similar to (near) each
other in one cluster and data instances that are very
different (far away) from each other into different clusters.
• Clustering is often called an unsupervised
learning task as no class values denoting an a
priori grouping of the data instances are given,
which is the case in supervised learning.
36
Amity Institute of Information Technology
Example
• Problem:
– Group customers based on purchasing behavior.
• Data (Unlabeled):
– Age, Annual Income, Spending Score
• Steps:
– Input the data (no labels).
– Choose number of clusters (e.g., 3).
– K-Means algorithm groups customers into clusters.
• Result:
– Cluster 1: Low spenders
– Cluster 2: Moderate spenders
– Cluster 3: High spenders
• Helps business target specific groups for marketing. 37
Amity Institute of Information Technology
Supervised learning vs. Unsupervised learning
• Supervised learning: discover patterns in the
data that relate data attributes with a target
(class) attribute.
– These patterns are then utilized to predict the values
of the target attribute in future data instances.
• Unsupervised learning: The data have no target
attribute.
– We want to explore the data to find some intrinsic
structures in them.
38
Amity Institute of Information Technology
Semi-supervised learning
• A machine learning approach that uses a small amount of
labeled data and a large amount of unlabeled data for
training.
• It combines the strengths of supervised and unsupervised
learning.
• Key Points:
– Cost-effective: Labeling data is expensive; unlabeled data is
plentiful.
– Learns from both: Labeled data gives accuracy, unlabeled data
improves generalization.
39
Amity Institute of Information Technology
Real-World Applications
• Speech Recognition (only a few labeled
transcriptions)
• Image Classification (millions of
unlabeled photos)
• Web Content Classification
• Medical Imaging (labels by experts are
expensive)
40
Amity Institute of Information Technology
Example – Image Classification
• Problem:
– Classify images of cats and dogs. You have:
– 500 labeled images (250 cats, 250 dogs)
– 10,000 unlabeled images
• Steps:
– Train initial model using the 500 labeled images.
– Use model to predict labels for 10,000 unlabeled images.
– Select confident predictions and add them to labeled set (pseudo-
labeling).
– Retrain model on larger dataset.
• Result:
– Model achieves higher accuracy than training on only 500 images.
41
Amity Institute of Information Technology
Taxonomy of the different ML Methods
Source Credit: An Introduction to Machine Learning, Fig. 1(a) doi:10.1002/cpt.1796 42
Amity Institute of Information Technology
ML Methods: Interpretability vs. Performance
Source Credit: An Introduction to Machine Learning, Fig. 1(b) doi:10.1002/cpt.1796 43
Amity Institute of Information Technology
Evolution of Machine Learning
44
Amity Institute of Information Technology
Evolution of Types of
Machine Learning
45
Amity Institute of Information Technology
Linear Algebra
Source Credit: Machine Learning, [Link]
[Link] 46
Amity Institute of Information Technology
What is Linear Algebra?
47
Amity Institute of Information Technology
Why do we need to know it?
48
Amity Institute of Information Technology
Scalar
49
Amity Institute of Information Technology
Vectors
50
Amity Institute of Information Technology
Geometry of Vectors
51
Amity Institute of Information Technology
Geometry of Vectors
52
Amity Institute of Information Technology
Dot Product and Angles
53
Amity Institute of Information Technology
Norm of a Vector
54
Amity Institute of Information Technology
Hyperplanes
55
Amity Institute of Information Technology
Hyperplanes
56
Amity Institute of Information Technology
Hyperplanes
57
Amity Institute of Information Technology
Matrices
58
Amity Institute of Information Technology
Matrices
59
Amity Institute of Information Technology
Matrices
60
Amity Institute of Information Technology
Matrices
61
Amity Institute of Information Technology
Matrices
62
Amity Institute of Information Technology
Matrix-Vector Products
63
Amity Institute of Information Technology
Matrix-Matrix Products
64
Amity Institute of Information Technology
Inverse of a Matrix
65
Amity Institute of Information Technology
Pseudo-Inverse of a Matrix
66
Amity Institute of Information Technology
Tensors
67
Amity Institute of Information Technology
Eigen Decomposition
68
Amity Institute of Information Technology
Eigen Decomposition
69
Amity Institute of Information Technology
Eigen Decomposition
70
Amity Institute of Information Technology
Differential Calculus
71
Amity Institute of Information Technology
Differential Calculus
72
Amity Institute of Information Technology
Optimization
73
Amity Institute of Information Technology
Optimization
[Link] 74
Amity Institute of Information Technology
Optimization
• Combinatorial optimization
– E.g.: Greedy search
• Convex optimization
– E.g.: Gradient descent
• Constrained optimization
– E.g.: Linear programming
75
Amity Institute of Information Technology
Probability Theory
Source Credit: Machine Learning, [Link]
[Link] 76
Amity Institute of Information Technology
Basics of Probability Theory
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 77
Amity Institute of Information Technology
Basics of Probability Theory
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 78
Amity Institute of Information Technology
Basics of Probability Theory: Random variables
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 79
Amity Institute of Information Technology
Basics of Probability Theory: Axioms of probability
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 80
Amity Institute of Information Technology
Basics of Probability Theory: Discrete Variables
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 81
Amity Institute of Information Technology
Basics of Probability Theory:
Multivariate Random Variables
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 82
Amity Institute of Information Technology
Basics of Probability Theory: Joint Probability Distribution
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 83
Amity Institute of Information Technology
Basics of Probability Theory: Marginal Probability Distribution
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 84
Amity Institute of Information Technology
Basics of Probability Theory:
Conditional Probability Distribution
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 85
Amity Institute of Information Technology
Bayes’ Theorem
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 86
Amity Institute of Information Technology
Independence
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 87
Amity Institute of Information Technology
Expected Value
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 88
Amity Institute of Information Technology
Variance
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 89
Amity Institute of Information Technology
Covariance
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 90
Amity Institute of Information Technology
Correlation
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 91
Amity Institute of Information Technology
Probability Distributions
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 92
Amity Institute of Information Technology
Probability Distributions
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 93
Amity Institute of Information Technology
Probability Distributions
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 94
Amity Institute of Information Technology
Cross-entropy
Slide Source Credit: Jeff Howbert — Machine Learning Math Essentials 95
Amity Institute of Information Technology
Overview of Target Function Representations
• In supervised machine learning, the target function (also called
hypothesis function, mapping function, or ground truth function)
refers to the ideal function that maps inputs (features) to outputs
(labels). Since this function is generally unknown, learning
algorithms approximate it using data.
• Different ML approaches use different representations for this
function. Choosing the right representation is crucial because it
affects accuracy, interpretability, efficiency, and generalization.
96
Amity Institute of Information Technology
Target Function Representations
97
Amity Institute of Information Technology
Types of ML Techniques
• Based on task: • Based on approach:
– Classification – Symbolic (Logic-
– Regression based)
– Clustering – Sub-symbolic (Neural
– Anomaly Detection Networks, Deep
Learning)
– Recommendation
– Evolutionary (Genetic
Algorithms)
98
Amity Institute of Information Technology
Hypothesis selection through cross validation
• What is Hypothesis Selection?
• Hypothesis space H: Set of all candidate models (e.g.,
linear models with different coefficients, decision trees of
different depths, neural networks with different
architectures).
• Goal: Select the hypothesis h∗∈H that generalizes best
to unseen data.
• Problem: Training error alone is not reliable, since a
complex model may fit training data perfectly but fail on
new data.
99
Amity Institute of Information Technology
Cross-Validation for Hypothesis Selection
k-Fold Cross-Validation Leave-One-Out Cross-
Validation (LOOCV)
Stratified Cross-
Validation
Ensures that each fold preserves the
class distribution (important for
imbalanced datasets).
100
Amity Institute of Information Technology
How Cross-Validation Helps in Hypothesis Selection?
• Avoids overfitting: Penalizes overly complex
hypotheses that don’t generalize well.
• Fair comparison: Each hypothesis is evaluated on the
same validation scheme.
• Model tuning: CV helps select not just the hypothesis
type but also hyperparameters (e.g., depth of decision
tree, regularization strength, number of hidden layers).
101
Amity Institute of Information Technology
Example Workflow
102
Amity Institute of Information Technology
Bias-Variance Trade-off in Hypothesis Selection
• Low bias, high variance (complex models): May fit training well
but CV error high.
• High bias, low variance (simple models): CV error high due to
underfitting.
• Best hypothesis: Minimizes expected generalization error, as
estimated by cross-validation.
Summary
103
Amity Institute of Information Technology
Some Key Machine Learning Definitions
• Model: A machine learning model can be a mathematical representation of a real-
world process. To generate a machine learning model you will need to provide
training data to a machine learning algorithm to learn from.
• Algorithm: Machine Learning algorithm is the hypothesis set that is taken at the
beginning before the training starts with real-world data. When we say Linear
Regression algorithm, it means a set of functions that define similar
characteristics as defined by Linear Regression and from those set of functions
we will choose one function that fits the most by the training data.
• Training: While training for machine learning, you pass an algorithm with training
data. The learning algorithm finds patterns in the training data such that the input
parameters correspond to the target. The output of the training process is a
machine learning model which you can then use to make predictions. This
process is also called “learning”.
• Regression: Regression techniques are used when the output is real-valued
based on continuous variables. For example, any time series data. This technique
involves fitting a line.
• Classification: In classification, you will need to categorize data into predefined
classes. For example, an email can either be ‘spam’ or ‘not spam’.
104
Amity Institute of Information Technology
Some Key Machine Learning Definitions
• Target: The target is whatever the output of the input variables. It could be the
individual classes that the input variables maybe mapped to in case of a classification
problem or the output value range in a regression problem. If the training set is
considered then the target is the training output values that will be considered.
• Feature: Features are individual independent variables that act as the input in your
system. Prediction models use features to make predictions. New features can also
be obtained from old features using a method known as ‘feature engineering’. More
simply, you can consider one column of your data set to be one feature. Sometimes
these are also called attributes. And the number of features are called dimensions.
• Label: Labels are the final output. You can also consider the output classes to be the
labels. When data scientists speak of labeled data, they mean groups of samples that
have been tagged to one or more labels.
• Overfitting: An important consideration in machine learning is how well the
approximation of the target function that has been trained using training data,
generalizes to new data. Generalization works best if the signal or the sample that is
used as the training data has a high signal to noise ratio. If that is not the case,
generalization would be poor and we will not get good predictions. A model is
overfitting if it fits the training data too well and there is a poor generalization of new
data.
105
Amity Institute of Information Technology
Some Key Machine Learning Definitions
• Regularization: Regularization is the method to estimate a
preferred complexity of the machine learning model so that the
model generalizes and the over-fit/under-fit problem is avoided.
This is done by adding a penalty on the different parameters of the
model thereby reducing the freedom of the model.
• Parameter and Hyper-Parameter: Parameters are configuration
variables that can be thought to be internal to the model as they
can be estimated from the training data. Algorithms have
mechanisms to optimize parameters. On the other hand,
hyperparameters cannot be estimated from the training data.
Hyperparameters of a model are set and tuned depending on a
combination of some heuristics and the experience and domain
knowledge of the data scientist.
106
Amity Institute of Information Technology
Suggested Video and Free Courses
• MIT Open Course Ware
– Probabilistic Systems Analysis and Applied Probability
[Link]
applied-probability-fall-2013/
107