Saad Assign 1 AI
Saad Assign 1 AI
Section: BSCS-B
Semester: 6th
Assignment 1
Question 1
Explain ID3 Algorithm with the help of appropriate example; calculate the entropy, information gain
and other factors on decision
Introduction:
The ID3 (Iterative Dichotomiser 3) algorithm is a decision tree learning algorithm used for building
decision trees from a given dataset. It is a greedy algorithm that constructs the decision tree in a
top-down, recursive manner by selecting the most informative attribute at each node to split the
data.
Example:
Let's consider the following dataset for playing tennis based on several attributes:
Entropy Calculation:
Where:
Information gain is a measure of how much entropy (or impurity) is reduced by splitting the dataset
on a particular attribute. The attribute with the highest information gain is chosen as the root node
of the decision tree.
Where:
• S is the current dataset
For example, let's calculate the information gain for the "Outlook" attribute:
Information Gain(S, Outlook) = 0.940 - ((5/14) * 0.971 + (4/14) * 0 + (5/14) * 0.971) Information
Gain(S, Outlook) = 0.246
Similarly, the information gain can be calculated for other attributes, and the attribute with the
highest information gain ("Outlook" in this case) is chosen as the root node of the decision tree.
The ID3 algorithm recursively constructs the decision tree by selecting the attribute with the
highest information gain at each node until all instances belong to the same class or there are no
more attributes left to split.
Outlook
/ \
/ \
Sunny Overcast
/ \ \
/ \ = Yes
High Normal
\ /
\ /
No Yes
In this decision tree, the root node is "Outlook." If the outlook is sunny, the next attribute to consider
is "Humidity." If the humidity is high, the decision is "No" for playing tennis; otherwise, the decision
is "Yes." If the outlook is overcast, the decision is always "Yes" for playing tennis.
Question 2
Introduction:
A Directed Acyclic Graph (DAG) is a directed graph with no cycles. In other words, it is a graph
where you cannot start from any node and traverse through the edges to return to the same node.
DAGs are commonly used to represent probabilistic models, such as Bayesian Networks.
Consider the following scenario: You have a burglar alarm installed in your house, and it can be
triggered by a burglar breaking in or by small earthquakes that are common in your area.
Additionally, you have two neighbors, John and Mary, who can potentially call you if they hear the
alarm.
We can represent this scenario using a DAG, where the nodes represent the random variables, and
the edges represent the causal relationships between them.
Burglar
/ \
/ \
/ \
Earthquake Alarm
\ / \
\ / \
\ / \
Call Call
• The "Burglar" and "Earthquake" nodes represent the potential causes of the alarm.
• The "Alarm" node represents the event of the alarm being triggered.
• The "Call John" and "Call Mary" nodes represent the events of John and Mary calling you
after hearing the alarm.
The edges in the DAG represent the causal relationships between the variables:
• The alarm can directly cause John and Mary to call you.
However, there are no direct edges between "Burglar" and "Call John" or "Call Mary," as the burglar
does not directly cause them to call; it is the alarm that triggers the call.
This DAG captures the conditional independence relationships between the variables. For example,
if we know the state of the "Alarm" node, the "Burglar" and "Earthquake" nodes become
independent of the "Call John" and "Call Mary" nodes. This property allows us to simplify the
calculations and make efficient inferences in probabilistic models.
DAGs are widely used in various domains, including machine learning, artificial intelligence, and
decision support systems, to represent and reason about complex probabilistic models.