Day 4 Session 1 PDF
Day 4 Session 1 PDF
Introduction to
Machine Learning and
its Applications.
Gloriya Mathew
Asst. Professor
Amal Jyothi College of Engineering
Kanjirappally.
Contents
Artificial Intelligence:
Machine Learning:
Definition.
How Machines Learn ?
Common Machine Learning Algorithms(Models).
KNN
Naïve Bayes
Decision Trees
Regression Model
Neural Networks
Support Vector Machine(SVM)
Evaluating Model Performance.
Improving Model performance.
Tools Used in Machine Learning.
Applications.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Artificial Intelligence ???
Intelligent Programs:
Programs conducting specific Intelligent Tasks.
Artificial Intelligence (cntd.)
Eg:- ``Sophia``
A social humanoid robot
Developed by Hanson
Robotics.
First public appearance in
Texas, US.
Able to display more than
50 facial expressions.
Participated in many high-
profile interviews.
Robot – ‘Sophia’ Interview
First robot to receive
citizenship of any country.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Artificial Intelligence - Examples.
Robotics.
Smartphones
Smart Cars and Drones.
Social Media.
Music and Media Streaming Services(youtube).
Video Games
Online Ads Network.
Navigation and Travel(Google Maps).
Banking and Finance sector.(Fraud Detection)
Smart Home Devices.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Artificial Intelligence (cntd.)
Machine Learning.
It is the Science of Teaching Machines How to Learn by
Themselves.
Focuses on the development of computer programs that can
change when exposed to new data.
Machine learning is about Predicting the future, based on the
past.
Algorithms or techniques that enable computer (machine) to
“learn” from data.
As intelligence requires knowledge, it is necessary for the
computers to acquire knowledge.
Related with many areas such as:
• Data Mining
• Statistics etc…
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Machine Learning (cntd.)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Machine Learning (cntd.)
How Machines Learn ?
Tom M. Mitchell states that:
“A machine learns whenever it is able to utilize its
‘an experience’ such that its performance
improves on similar experiences in the future”.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn?
Conditions
necessary for
Human brains are computers to
naturally capable of learn must be
learning from birth. made Explicit.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn?
Regardless of whether the learner is a Human or
Machine, the basic learning process is similar.
It can be divided into 4 - Interrelated Components:
Data storage
Abstraction
Generalization
Evaluation Learning
Process
Same
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn ? (cntd.)
1. Data Storage:
Utilizes observation, memory, and recall to provide a factual
basis for further reasoning.
All learning must begin with data.
Humans brain
Computers uses hard disk drives, flash memory, and
random access memory (RAM) in combination with a
Central Processing Unit (CPU).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn ? (cntd.)
2. Abstraction:
Involves the translation of stored data into broader
representations and concepts.
Basis of Knowledge Representation.
During this process, the computer summarizes stored
raw data using a model;
Model An explicit description of the patterns
within the data.
Mathematical Equations.
Relational Diagrams.( trees, graphs...)
Logical if/else rules.
Groupings of data known as clusters.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn ? (cntd.) :
Abstraction(cntd.)
Training (Model Training)
The process of fitting a model to a dataset is known as training.
When the model has been trained, the data is transformed into
an abstract form that summarizes the original information.
Eg: Discovery of gravity.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn ? (cntd.) :
3. Generalization:
Uses abstracted data to create knowledge and inferences
that drive action in new contexts.
It involves Reduction of data set into a manageable number
of important findings.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn ? (cntd.) :
4. Evaluation:
To Evaluate/Measure the performance of the model &
Use this information to inform additional training if needed.
The model is evaluated using a new Test Dataset.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
How Machines Learn ? (cntd.) :
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Machine Learning in Practice.
5-step process:
1. Data Collection:
2. Data Exploration and Preparation:
Checking the Quality of data & Prepare data for learning process.
3. Model Training:
Selection of an appropriate algorithm, and the algorithm will represent
the data in the form of a model.
4. Model Evaluation:
Evaluating the accuracy of the model using the test data set.
5. Model Improvement:
If better performance is needed , use advanced strategies to improve the
performance of the model.
Switch to different model.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Types of Machine Learning Algorithms:
1. Supervised Learning.
2. Unsupervised Learning.
3. Reinforcement Learning.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Supervised Learning:
Supervised learning is where you have Input Variables (X) and an Output
Variable (Y) and you use an algorithm to learn the mapping function from the
input to the output.
Y = f(X)
In supervised learning, we use known or labeled data for the Training
Dataset. Since, Data Label is known; So, the learning is, therefore,
Supervised; i.e., Directed into Successful Execution.
o Eg:-
o K-nearest neighbors
o Naive Bayes.
o Decision trees
o Random forest
o Regression,..
Eg:- To Predict whether
“An e-mail message is spam/NOT.”
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Unsupervised Learning.
• Have Input Data (X) and No corresponding Output Variables.
Goal:
• To “model the underlying structure or distribution in the data”
in order to learn more about the Data.
•Eg:-
•Clustering.
• Pattern Discovery.
•Association Rules Mining
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Reinforcement Learning.
Reinforcement Learning is said to be the hope of true artificial
intelligence.
Learning from Mistakes.
it is the training of machine learning models to make a sequence
of decisions.
A start state and end state are defined.
The agents discovers the path and the relationships on its own.
It is a slightly complex as compared to traditional machine
learning.
eg:- Chess game
Self driven cars etc..
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Common Machine Learning Algorithms.
KNN
Naïve Bayes
Decision Trees
Regression Model
Neural Networks
Support Vector Machine(SVM)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
The KNN (K-Nearest Neighbors) Algorithm:
Widely used.
k a variable implying that any number of nearest
neighbors could be used.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
The KNN (K-Nearest Neighbors) Algorithm(cntd.):
Uses:
Computer vision applications:
(Optical Character Recognition and Facial Recognition).
Predicting whether a person will enjoy a movie or
music .
Identifying patterns in genetic data.
Classification
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
The KNN (K-Nearest Neighbors) Algorithm(cntd.):
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Is Tomato a Fruit or Vegetable?
Locating the tomato's nearest
neighbors requires a distance
function / A formula that measures
the similarity between the two
instances.
k-NN algorithm uses Euclidean
distance:
p & q examples to be compared,
each having n - features.
p1 the value of the first feature
of example p;
q1 the value of the first feature of
example q:
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Euclidean Distance (cntd.):
•
• K=1; Orange FRUIT Tomato==FRUIT.
• K=3; Orange, Grapes, Nuts Among these majority class is
Fruit Tomato = FRUIT.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Naive Bayes' classifier
A probabilistic Machine Learning Model that is
used for classification task.
Probabilistic Classifier:
A classifier that is able to predict, given a sample input, a
probability distribution over a set of classes.
Eg:- Meteorologist – weather forecast- “70 % chance of rain
“.
A 70% chance of rain 7 out of the 10 past cases with
similar conditions, precipitation(weather condition) occurred
somewhere in the area.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Naive Bayes' classifier(cntd.)
Based on the Bayes theorem.
It captures the chance(probability) that an event will
occur in the light of the available evidence.
Bayes Theorem:
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Naive Bayes' classifier(cntd.)
Uses:
Text Classification (eg:- spam e-mail filtering).
P(spam|congratulations):= 0.80.
• probability is 80 % that a message
is spam, given that it contains the
word congratulations.
• In light of this result, any message
containing this term should
probably be filtered.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Decision Trees(cntd).
Decision Trees(cntd).
Benefits:
Interpretability: Easy to Interpret, understand, and visualize
Can handle both Numerical and Categorical Data.
Simple to prepare and fit model.
Uses:
1. Credit scoring models An applicant to be rejected /NOT.
2. Marketing studies of customer behavior such as Satisfied or
NOT.
3. Diagnosis of medical conditions based on laboratory
measurements, symptoms, or the rate of disease progression.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Decision Trees(cntd).
Divide and Conquer.
Decision trees are built using a heuristic called Recursive
Partitioning.
commonly known as Divide and Conquer:
It splits the data into subsets, which are then split repeatedly
into even smaller subsets, and so on &
Until the process stops when the algorithm determines the
data within the subsets are sufficiently homogenous, or
another stopping criterion has been met.
STOPPING Conditions:
1. All (or nearly all) of the examples at the node have the same class.
2. There are no remaining features to distinguish among the examples.
3. The tree has grown to a predefined size limit.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Regression Methods:
1. Simple Linear Regression
2. Multiple Linear Regression
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Regression.
A Supervised Machine Learning Algorithm.
Specifies the mathematical relationship between a single numeric
dependent variable (the value to be predicted) and one or more
numeric independent variables (the predictors).
eg:- Income related to education and job experience.
Regression equations model data using a Slope-intercept Format.
y = a + bx. y Dependent variable
x Independent variable.
b Slope
a Intercept
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Regression(cntd.).
1. Simple Linear Regression:
Defines a Mathematical Relationship between a dependent
variable and a Single independent variable using a Line.
defined by equation :
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Regression(cntd.).
2. Multiple Linear Regression
(Multiple Regression):
Mathematical Relationship between a dependent
variable Two or more independent variables.
General form:
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Other Regression Methods:
Logistic Regression:
Poisson Regression:
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Black Box Methods:
1. Neural Networks &
2. Support Vector Machines ( SVM )
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
An Artificial Neural Network (ANN)
A supervised Machine Learning Algorithm.
Designed as Conceptual Models of Human Brain Activity.
ANN uses a Network of Artificial Neurons or nodes to solve
learning problems.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
An Artificial Neural Network (ANN) (cntd.)
Applications:
ANNs are versatile learners that can be applied to
nearly any learning task:
– Classification,
– Numeric prediction
– Unsupervised pattern recognition.
• Speech and handwriting recognition programs.
• Automation of smart devices.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
An Artificial Neural Network (ANN) (cntd.)
Directed Network Diagram:
Defines a relationship between the input signals received by
the dendrites (x variables), and the output signal (y variable).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
An Artificial Neural Network (ANN) (cntd.)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
An Artificial Neural Network (ANN) (cntd.)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
An Artificial Neural Network (ANN) (cntd.)
1. An activation function:
Transforms a neuron's combined input signals into a single
output signal to be broadcasted further in the network.
• eg: Threshold Activation Function.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
An Artificial Neural Network (ANN) (cntd.)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Network Topology (cntd.).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Network Topology (cntd.).
Single-layer Networks:
– Only One Layer.
Multilayer Network:
Create more Complex Networks by adding additional Hidden
layers.
Single Layer Network: Multilayer Network:
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Network Topology (cntd.).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Network Topology (cntd.).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Network Topology (cntd.).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Deep Learning
Deep Neural Network (DNN):
A neural network with Multiple
Hidden Layers.
Practice of training DNN
Deep Learning.
Applications:
Facebook - Identifying faces
in photographs by using deep
learning.
Speech Recognition.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Support Vector
Machines (SVM):
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Support Vector Machines(SVM)
Goal of SVM:
To create a flat boundary called a hyperplane, which divides
the space to create fairly homogeneous partitions on either
side.
SVM Learning Combines :
KNN + Linear Regression.
The combination is extremely powerful.
To model highly complex relationships.
Uses:
Classification
Numeric prediction.
Pattern recognition.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Support Vector Machines(cntd.)
Applications:
1. Gene Expression Data Classification:
In the field of bioinformatics to identify cancer or
other genetic diseases.
2. Text categorization:
Identification of the language used in a document
classification of documents by subject matter.
3. The detection of rare yet important events:
Combustion engine failure, security breaches, or
earthquakes.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Hyperplanes
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Hyperplanes (cntd..)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Maximum Margin Hyperplane(MMH):
Creates the greatest separation between the two classes.
Support Vectors:
Points from each class that are the
closest to the MMH;
Using the support vectors alone, it is
possible to define the MMH.
This is a key feature of SVMs;
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Clustering
• Unsupervised learning algorithms
• It mainly deals with finding a structure or pattern in a collection
of uncategorized data.
• Clustering algorithms will process your data and find natural
clusters(groups) if they exist in the data.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Evaluating Model Performance:
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering.
Evaluating Model Performance(cntd):
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Evaluating Model Performance(cntd):
Confusion Matrices
Prepared
Prepared by:by: Gloriya
Gloriya Mathew,
Mathew, Asst.
Asst. Professor,
Professor, Amal
Amal Jyothi
Jyothi College
College of of Engineering
Engineering
Evaluating Model Performance(cntd):
Correct Predictions:
Predicted Value = Actual Value
a correct classification.
Diagonal Elements in the
confusion matrix.(denoted by O).
Incorrect Predictions:
Predicted Value Differs from the
Actual Value.
The off-diagonal matrix cells.
Confusion Matrix (cntd):
Positive Class:
• The Class of Interest is known as the positive class;
• All others are known as Negative Class.
Predictions fall into one of the 4- categories:
1. True Positive (TP): Correctly classified as the class of interest.
2. True Negative (TN): Correctly classified as NOT the class of
interest.
3. False Positive (FP): Incorrectly classified as the class of
interest.
4. False Negative (FN): Incorrectly classified as NOT the class of
interest.
Preparedby:
Prepared by:Gloriya
GloriyaMathew,
Mathew, Asst.Professor,
Asst. Professor, AmalJyothi
Amal JyothiCollege
CollegeofofEngineering
Engineering
Using Confusion Matrices to Measure Performance.
Error Rate:
Proportion of the Incorrectly Classified examples:
Error rate = 1 - accuracy.
Error Rate=(FP+FN)/(TP+TN+FP+FN)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Evaluating Model Performance(cntd):
Precision:
Proportion of positive examples that are truly positive;
Recall :
Measure of how complete the results are.
Eg:-SMS spam filter has a high recall if the majority of spam
messages are correctly identified.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
The Holdout Method
The procedure of partitioning data into Training Datasets
and Test Datasets :
Training Dataset(2/3) Used to Generate The Model;
Test Dataset(1/3) To Generate Predictions for
evaluation.
Validation Dataset Used for Iterating and Refining
The Model or models chosen.
Eg:- A typical split :
Training DS(50%), Test DS(25%), Validation DS(25%).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
The Holdout Method
Improving
Model Performance:
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Improving Model Performance:
Meta-learning:
• Technique of combining and managing the
predictions from multiple models to form a powerful
model.
Ensemble methods:
Meta-learning approach
Idea:
By combining multiple weaker learners, a stronger
learner is created.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Improving Model Performance(cntd.)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Improving Model Performance(cntd.)
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Improving Model Performance(cntd.)
Bagging
One of the first ensemble
method.
Widespread Acceptance.
Uses a technique called
bootstrap aggregating or
bagging.
The models' predictions are
combined using Voting (for
classification) or Averaging
(for numeric prediction).
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Improving Model Performance(cntd.)
Boosting
Another common ensemble-based method
It boosts the performance of weak learners to attain the
performance of stronger learners.
Similar to bagging.
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Improving Model Performance(cntd.)
Random Forests.
(Decision Tree Forests.)
Improving Model Performance(cntd.)
Random Forests (Decision Tree Forests.)
Ensembles of decision trees.
After the ensemble of trees (the forest) is generated,
the model uses a vote to combine the trees' predictions.
randomForest()
Prepared by: Gloriya Mathew, Asst. Professor, Amal Jyothi College of Engineering
Tools & Languages.
• Languages: • Visualization tools:
R
• Tableau
Python
• QlikView
Java
Javascript • D3.js
SAS
Julia • Other tools commonly
• Databases: used:
SQL
• Excel
Oracle
Hadoop • Powerpoint
Applications of Machine Learning in day-to-day life
Thank You.