Unit 1 ML
Unit 1 ML
Prepared by
Mrs.Nilam Patil
1
Unit-1 Introduction to ML Syllabus
• classic and adaptive machines 1hr
• Only learning matters 1hr
• Beyond machine learning - deep learning and
bio-inspired adaptive systems 1hr
• Machine learning and big data 1hr
• Important Elements in Machine Learning
• Data formats ½ hr
• Learnability ½ hr
• Statistical learning approaches 1hr
• Elements of information theory 1hr
2
Classic and Adaptive machines
5
APPLICATIONS OF MACHINE LEARNING
• Google Search
• Stock Predictions
• Robotics-‘Sophia’ introduced which could
actually behave like humans.
• Social Media Services- Face Recognition , Add
as friend in facebook or people you may know
• Email Spam and Malware Filtering- C 4.5
Decision Tree Induction
• Over 325, 000 malwares are detected everyday and
each piece of code is 90–98% similar to its previous
versions. 6
Generic Representation of a Classical System that
receives some input values, processes them, and
produces output results:
•
7
• Machine learning algorithms are described as
learning a target function (f) that best maps
input variables (X) to an output variable (Y).
Y = f(X)
• This is a general learning task where we would like to make
predictions in the future (Y) given new examples of input
variables (X).
• It is harder than you think. There is also error (e) that is
independent of the input data (X).
Y = f(X) + e
• This error might be error such as not having enough attributes
to sufficiently characterize the best mapping from X to Y. This
error is called irreducible error because no matter how good
we get at estimating the target function (f), we cannot reduce
this error. 8
Schematic Representation of an adaptive system:
9
Adaptive Learning- Spam filtering, Natural
Language Processing, visual tracking with a
webcam or a smartphone, and predictive
analysis are only a few applications that
revolutionized human-machine interaction and
increased our expectations.
• Such a system isn't based on static or permanent
structures (model parameters and architectures)
but rather on a continuous ability to adapt its
behavior to external signals (datasets or real-time
inputs) and, like a human being, to predict the
future using uncertain and fragmentary pieces of
information.
10
Machine Learning Matters
• Machine learning is to study, engineer, and improve
mathematical models which can be trained (once or
continuously) with context-related data (provided by a
generic environment), to infer the future and to make
decisions without complete knowledge of all influencing
elements (external factors).
• In other words, an agent (which is a software entity that
receives information from an environment, picks the
best action to reach a specific goal, and observes the
results of it) adopts a statistical learning approach,
trying to determine the right probability distributions
and use them to compute the action (value or decision)
that is most likely to be successful (with the least error).
11
Machine learning is a sort of
modern magic.
• Prediction- Even in the most complex
scenarios, such as image classification with
convolutional neural networks, every piece of
information (geometry, color, peculiar
features, contrast, and so on) is already
present in the data and the model has to be
flexible enough to extract and learn it
permanently.
12
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)
• The goal is to approximate the mapping
function so well that when you have new
input data (x) that you can predict the output
variables (Y) for that data.
13
• It is called supervised learning because the
process of an algorithm learning from the
training dataset can be thought of as a
teacher supervising the learning process.
• We know the correct answers, the algorithm
iteratively makes predictions on the training
data and is corrected by the teacher.
• Learning stops when the algorithm achieves
an acceptable level of performance.
14
• Supervised learning problems can be further grouped into
regression and classification problems.
• Classification: A classification problem is when the output
variable is a category, such as “red” or “blue” or “disease” and
“no disease”.
• Regression: A regression problem is when the output variable is a
real value, such as “dollars” or “weight”.
• Some common types of problems built on top
of classification and regression include recommendation and time
series prediction respectively.
• Some popular examples of supervised machine learning
algorithms are:
• Linear regression for regression problems.
• Random forest for classification and regression problems.
• Support vector machines for classification problems.
15
Classification example
• Sometimes, instead of predicting the actual category, it's
better to determine its probability distribution.
• For example, an algorithm can be trained to recognize a
handwritten alphabetical letter, so its output is
categorical (in English, there'll be 26 allowed symbols).
• On the other hand, even for human beings, such a
process can lead to more than one probable outcome
when the visual representation of a letter isn't clear
enough to belong to a single category.
• That means that the actual output is better described by
a discrete probability distribution (for example, with 26
continuous values normalized so that they always sum
up to 1).
16
Problem with Supervised learning
• overfitting, which causes an overlearning due
to an excessive capacity.
• ability to
predict correctly only the
samples used for training, while the
error for the remaining ones is
always very high
17
Common Supervised Learning
Applications include:
• Predictive analysis based on regression or
categorical classification Spam detection
• Pattern detection
• Natural Language Processing
• Sentiment analysis
• Automatic image classification
• Automatic sequence processing (for
example, music or speech)
18
19
Unsupervised Machine Learning
• Unsupervised learning is where you only have
input data (X) and no corresponding output
variables.
• The goal for unsupervised learning is to model the
underlying structure or distribution in the data in
order to learn more about the data.
• These are called unsupervised learning because
unlike supervised learning above there is no
correct answers and there is no teacher.
Algorithms are left to their own devises to
discover and present the interesting structure in
the data. 20
• Unsupervised learning problems can be further
grouped into clustering and association problems.
• Clustering: A clustering problem is where you want to
discover the inherent groupings in the data, such as
grouping customers by purchasing behavior.
• Association: An association rule learning problem is
where you want to discover rules that describe large
portions of your data, such as people that buy X also
tend to buy Y.
• Some popular examples of unsupervised learning
algorithms are:
• k-means for clustering problems.
• Apriori algorithm for association rule learning
problems. 21
Commons Unsupervised Applications
include:
• Object segmentation (for example, users,
products, movies, songs, and so on) Similarity
detection
• Automatic labeling
22
Semi-Supervised Machine Learning
• Problems where you have a large amount of input
data (X) and only some of the data is labeled (Y) are
called semi-supervised learning problems.
• These problems sit in between both supervised and
unsupervised learning.
• A good example is a photo archive where only some of
the images are labeled, (e.g. dog, cat, person) and the
majority are unlabeled.
• Many real world machine learning problems fall into
this area. This is because it can be expensive or time-
consuming to label data as it may require access to
domain experts. Whereas unlabeled data is cheap and
easy to collect and store. 23
Summary
• Supervised: All data is labeled and the
algorithms learn to predict the output
from the input data.
• Unsupervised: All data is unlabeled and
the algorithms learn to inherent structure
from the input data.
• Semi-supervised: Some data is labeled but
most of it is unlabeled and a mixture of
supervised and unsupervised techniques
can be used. 24
Reinforcement learning
• Reinforcement learning is also based on
feedback provided by the environment.
However, in this case, the information is more
qualitative and doesn't help the agent in
determining a precise measure of its error.
• this feedback is usually called reward
(sometimes, a negative one is defined as a
penalty) and it's useful to understand whether
a certain action performed in a state is
positive or not.
25
an action can also be imperfect, but in terms of a global
policy it has to offer the highest total reward.
• Reinforcement Learning is a framework for learning where
an agent interacts with an environment and receives a reward
for each interaction. The goal is to learn to accumulate as much
reward as possible over time.
• The real advantage these systems have over conventional supervised learning
is illustrated by this example I like a lot:
• Supervised Learning: Let us say that you know how to play chess. We record
you playing games against a lot of people. Now we train a system in the
supervised fashion to learn from your examples and call it KidPlayer. Let us
say that we train another system on Vishwanathan Anand’s games and call
this ProPlayer. Obviously the “policy” learned by KidPlayer will be an inferior
player to the policy learned by ProPlayer because of the different
capabilities of the teacher.
• Reinforcement Learning: In this setting, you make an agent play Chess against
someone (usually against another copy of itself) and give it a reward for every
time it wins a game. 26
• to learn the best policy for playing Atari video games and to
teach an agent how to associate the right action with an input
representing the state (usually a screenshot or a memory
dump).
• In the following figure, there's a schematic representation of a
deep neural network trained to play a famous Atari game.
• As input, there are one or more subsequent screenshots (this
can often be enough to capture the temporal dynamics as well).
• They are processed using different layers (discussed briefly
later) to produce an output that represents the policy for a
specific state transition.
• After applying this policy, the game produces a feedback (as a
reward-penalty), and this result is used to refine the output
until it becomes stable (so the states are correctly recognized
and the suggested action is always the best one) and the total
reward overcomes a predefined threshold.
27
Atari Video Game
28
schematic representation of a deep neural
network trained to play a famous Atari game.
29
AI vs ML vs Deep Learning
30
Machine Learning vs Deep Learning
31
Deep Learning
• Machine learning concerned with algorithms inspired by the
structure and function of the brain called artificial neural
networks.
• A deep neural network (DNN) is an artificial neural Network (ANN)
with multiple hidden layers between the input and output layers.
• DNNs are typically feedforward networks in which data flows from
the input layer to the output layer without looping back.
• where as feedforward with Backpropagation ( is a common
method for training a neural network in back direction with
change of weights according to error) forms a better DNN.
• Recurrent neural networks (RNNs), in which data can flow in any
direction, are used for applications for language purposes.
• Convolutional neural networks (CNNs) are used in computer
vision. CNNs have been applied to acoustic modeling for automatic
speech recognition
32
Beyond Machine Learning - Deep
Learning and bio-inspired adaptive
systems
• many researchers started training bigger and
bigger models, built with several different
layers (that's why this approach is called deep
learning), to solve new challenging problems.
• The availability of cheap and fast computers
allowed them to get results in acceptable
timeframes and to use very large datasets
(made up of images, texts, and animations).
33
• The idea behind these techniques is to create
algorithms that work like a brain
• neurosciences and cognitive psychology.
• In particular, there's a growing interest in
pattern recognition and associative memories
whose structure and functioning are similar to
what happens in the neocortex. Such an
approach also allows simpler algorithms called
model- free
• It is based on generic learning techniques and
repeating experiences.
• testing different architectures and
optimization algorithms is quite simpler 34
Common Deep learning applications include:
• Image classification, Real-time visual tracking
• Autonomous car driving , Logistic optimization
• Bioinformatics, Speech recognition
35
36
Data Format
• Labeled data: Data consisting of a set
of training examples, where each example is
a pair consisting of an input and a desired
output value (also called the supervisory
signal, labels, etc)
• Classification: The goal is to predict discrete
values, e.g. {1,0}, {True, False}, {spam, not
spam}.
• Regression: The goal is to predict continuous
values, e.g. home prices.
37
Important Elements in Machine
Learning
• Data formats
• In a supervised learning problem, there will
always be a dataset, defined as a finite set of
real vectors with m features each:
38
• Feature vector: A typical setting for machine learning
is to be given a collection of objects (or data points),
each of which is characterised by several different
features.
• Features can be of different sorts: e.g., they might be
continuous (say, real- or integer-valued) or
categorical (for instance, a feature for colour can
have values like green, blue, red ).
• A vector containing all of the feature values for a
given data point is called the feature vector;
• if this is a vector of length m, then one can think of
each data point as being mapped to a m-dimensional
vector space (in the case of real-valued features, this
is R m ), called the feature space. 39
• This means all variables belong to the same
distribution D, and considering an arbitrary
subset of m values, it happens that:
40
• Categorical examples are
41
interpretation can be expressed in terms of
additive noise:
45
• there's an example of a dataset whose points
must be classified as red (Class A) or blue (Class
B).
• Three hypotheses are shown: the first one (the
middle line starting from left) misclassifies one
sample,
• while the lower and upper ones misclassify 13
and 23 samples respectively:
• the first hypothesis is optimal and should be
selected; however, it's important to understand
an essential concept which can determine a
potential overfitting
46
47
• The blue classifier is linear while the red one is cubic.
At a glance, non-linear strategy seems to perform
better, because it can capture more expressivity,
thanks to its concavities.
• However, if new samples are added following the
trend defined by the last four ones (from the right),
they'll be completely misclassified.
• In fact, while a linear function is globally better but
cannot capture the initial oscillation between 0 and
4, a cubic approach can fit this data almost perfectly
but, at the same time, loses its ability to keep a
global linear trend.
48
Underfitting and overfitting
• Underfitting: It means that the model isn't able to
capture the dynamics shown by the same training
set (probably because its capacity is too limited).
• Overfitting: the model has an excessive capacity
and it's not more able to generalize considering the
original dynamics provided by the training set. It
can associate almost perfectly all the known
samples to the corresponding output values, but
when an unknown input is presented, the
corresponding prediction error can be very high.
49
low-capacity (underfitting), normal-capacity
(normal fitting), and excessive capacity
(overfitting):
50
Error measures
• In general, when working with a supervised
scenario, we define a non-negative error
measure em which takes two arguments
(expected & predicted output ) and allows us
to compute a total error value over the whole
dataset (made up of n samples):
51
• This value is also implicitly dependent on the
specific hypothesis H through the parameter
set, therefore optimizing the error implies
finding an optimal hypothesis
52
53
• This measure is also called loss function
because its value must be minimized through
an optimization problem.
• When it's easy to determine an element which
must be maximized, the corresponding loss
function will be its reciprocal.
• Another useful loss function is called zero-
one-loss and it's particularly efficient for
binary classifications (also for one-vs-rest
multiclass strategy):
54
• generic (and continuous) loss function can be
expressed in terms of potential energy:
•
58
• For example, we could think about rules (hypotheses)
like: "If there are more than five blacklisted words" or "If
the message is less than 20 characters in length" then
"the probability of spam is high" (for example, greater
than 50 percent). However, without assigning
probabilities, it's difficult to generalize when the dataset
changes (like in a real world antispam filter). We also
want to determine a partitioning threshold (such as
green, yellow, and red signals) to help the user in
deciding what to keep and what to trash.
• As the hypotheses are determined through the dataset
X, we can also write (in a discrete form):
59
• In this example, it's quite easy to determine the value of each
term. However, in general, it's necessary to introduce the
Bayes formula
62
Maximum-likelihood learning
• We have defined likelihood as a filtering term
in the Bayes formula. In general, it has the
form of:
64
Elements of information theory
• A machine learning problem can also be analyzed in
terms of information transfer or exchange. Our
dataset is composed of n features, which are
considered independent (for simplicity, even if it's
often a realistic assumption) drawn from n different
statistical distributions.
• Therefore, there are n probability density functions
pi(x) which must be approximated through other n
qi(x) functions.
• In any machine learning task, it's very important to
understand how two corresponding distributions
diverge and what is the amount of information we
lose when approximating the original dataset. 65
The most useful measure is called
entropy:
67
• In order to understand how a machine learning
approach is performing, it's also useful to introduce a
conditional entropy or the uncertainty of X given the
knowledge of Y:
68
• Intuitively, when X and Y are independent,
they don't share any information. However, in
machine learning tasks, there's a very tight
dependence between an original feature and
its prediction, so we want to maximize the
information shared by both distributions.
• If the conditional entropy is small enough (so
Y is able to describe X quite well), the mutual
information gets close to the marginal entropy
H(X), which measures the amount of
information we want to learn.
69
References
• Russel S., Norvig P., Artificial Intelligence: A Modern Approach, Pearson
• Valiant L., A Theory of the Learnable, Communications of the ACM, Vol. 27, No. 11
(Nov. 1984)
• Hastie T., Tibshirani R., Friedman J., The Elements of Statistical Learning: Data
Mining, Inference and, Prediction, Springer
• Aleksandrov A.D., Kolmogorov A.N, Lavrent'ev M.A., Mathematics: Its contents,
Methods, and Meaning, Courier Corporation
• https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-
algorithms
70