5 Learning
5 Learning
An agent is learning if it improves its performance on future tasks after making observations about
the world.
Why would we want an agent to learn? If the design of the agent can be improved, why wouldn’t the
designers just program in that improvement to begin with? There are three main reasons.
First, the designers cannot anticipate all possible situations that the agent might find itself in.
For example, a robot designed to navigate mazes must learn the layout of each new maze it
encounters.
Second, the designers cannot anticipate all changes over time; a program designed to predict
tomorrow’s stock market prices must learn to adapt when conditions change from boom to
bust.
Third, sometimes human programmers have no idea how to program a solution themselves.
For example, most people are good at recognizing the faces of family members, but even the
best programmers are unable to program a computer to accomplish that task, except by using
learning algorithms.
FORMS OF LEARNING
Any component of an agent can be improved by learning from data. The improvements, and the
techniques used to make them, depend on four major factors:
• Which component is to be improved.
• What prior knowledge the agent already has.
• What representation is used for the data and the component.
• What feedback is available to learn from.
Learning a (possibly incorrect) general function or rule from specific input–output pairs is called
inductive learning.
There are three types of feedback that determine the three main types of learning:
In unsupervised learning the agent learns patterns in the input even though no explicit
feedback is supplied. The most common unsupervised learning task is clustering: detecting
potentially useful clusters of input examples. For example, a taxi agent might gradually
develop a concept of “good traffic days” and “bad traffic days” without ever being given
labeled examples of each by a teacher.
Decision tree induction is one of the simplest and yet most successful forms of machine learning.
We first describe the representation—the hypothesis space—and then show how to learn a good
hypothesis.
A decision tree represents a function DECISION TREE that takes as input a vector of
attribute values and returns a “decision”—a single output value. The input and
output values can be discrete or continuous. For now we will concentrate on
problems where the inputs have discrete values and the output has exactly two
possible values; this is Boolean classification, where each example input will be
classified as true (a positive example) or false (a negative example).
A decision tree reaches its decision by performing a sequence of tests. Each
internal node in the tree corresponds to a test of the value of one of the input
attributes, Ai, and the branches from the node are labeled with the possible values
of the attribute, Ai =vik.
Each leaf node in the tree specifies a value to be returned by the function. The
decision tree representation is natural for humans; indeed, many “How To” manuals
(e.g., for car repair) are written entirely as a single decision tree stretching over
hundreds of pages.
o Decision Tree is a Supervised learning technique that can be used for both
classification and Regression problems, but mostly it is preferred for solving
Classification problems. It is a tree-structured classifier, where internal nodes
represent the features of a dataset, branches represent the decision
rules and each leaf node represents the outcome.
o In a Decision tree, there are two nodes, which are the Decision Node and Leaf
Node. Decision nodes are used to make any decision and have multiple branches,
whereas Leaf nodes are the output of those decisions and do not contain any further
branches.
o The decisions or the test are performed on the basis of features of the given dataset.
o It is a graphical representation for getting all the possible solutions to a
problem/decision based on given conditions.
o It is called a decision tree because, similar to a tree, it starts with the root node,
which expands on further branches and constructs a tree-like structure.
o In order to build a tree, we use the CART algorithm, which stands
for Classification and Regression Tree algorithm.
o A decision tree simply asks a question, and based on the answer (Yes/No), it further
split the tree into subtrees.
o Below diagram explains the general structure of a decision tree:
o Decision Trees usually mimic human thinking ability while making a decision, so it
is easy to understand.
o The logic behind the decision tree can be easily understood because it shows a tree-
like structure.
Leaf Node: Leaf nodes are the final output node, and the tree cannot be segregated further after
getting a leaf node.
Splitting: Splitting is the process of dividing the decision node/root node into sub-nodes
according to the given conditions.
Pruning: Pruning is the process of removing the unwanted branches from the tree.
Parent/Child node: The root node of the tree is called the parent node, and other nodes are
called the child nodes.
In a decision tree, for predicting the class of the given dataset, the algorithm starts from the
root node of the tree. This algorithm compares the values of root attribute with the record
(real dataset) attribute and, based on the comparison, follows the branch and jumps to the
next node.
For the next node, the algorithm again compares the attribute value with the other sub-
nodes and move further. It continues the process until it reaches the leaf node of the tree.
The complete process can be better understood using the below algorithm:
o Step-1: Begin the tree with the root node, says S, which contains the complete dataset.
o Step-2: Find the best attribute in the dataset using Attribute Selection Measure (ASM).
o Step-3: Divide the S into subsets that contains possible values for the best attributes.
o Step-4: Generate the decision tree node, which contains the best attribute.
o Step-5: Recursively make new decision trees using the subsets of the dataset created in step
-3. Continue this process until a stage is reached where you cannot further classify the
nodes and called the final node as a leaf node.
Example: Suppose there is a candidate who has a job offer and wants to decide whether he
should accept the offer or Not. So, to solve this problem, the decision tree starts with the
root node (Salary attribute by ASM). The root node splits further into the next decision
node (distance from the office) and one leaf node based on the corresponding labels. The
next decision node further gets split into one decision node (Cab facility) and one leaf node.
Finally, the decision node splits into two leaf nodes (Accepted offers and Declined offer).
Consider the below diagram:
o Information Gain
o Gini Index
1. Information Gain:
o Information gain is the measurement of changes in entropy after the segmentation of a
dataset based on an attribute.
o It calculates how much information a feature provides us about a class.
o According to the value of information gain, we split the node and build the decision tree.
o A decision tree algorithm always tries to maximize the value of information gain, and a
node/attribute having the highest information gain is split first. It can be calculated using
the below formula:
Entropy is defined as the randomness or measuring the disorder of the information being processed
in Machine Learning. Further, in other words, we can say that entropy is the machine learning metric that
measures the unpredictability or impurity in the system.
Where,
A too-large tree increases the risk of overfitting, and a small tree may not capture all the
important features of the dataset. Therefore, a technique that decreases the size of the
learning tree without reducing accuracy is known as Pruning. There are mainly two types
of tree pruning technology used: