Professional Documents
Culture Documents
Ibatasm Mateen (18-Arid-5157) AI Theory BSCS-6C
Ibatasm Mateen (18-Arid-5157) AI Theory BSCS-6C
To be filled by Student
Q1 Using Decision Tree algorithm on the following dataset to draw ROOT node only.
(Where fast is output attribute)
Answer:
S= Fast= [yes, no]
S1= [5+ , 10-]
Entropy(s)=-5/15 log25/15-10/15log210/15
=0.333+0.3899 = 0.7232
Values(Engine)= [Small, Medium, large ]
SSmall [ 1+,5- ]
SMedium [2+,3- ]
Slarge [2+,2-]
Gain (S1 Engine)= Entropy(S)-∑|Sv|/|S| Entropy(Sv){ Small, Medium,large,}
Gain (S1 Engine)= Entropy(S)-6/15 (SSmall )-5/15 Entropy(SMedium)-4/15 Entropy(Slarge )
Entropy (Small)=-1/6 log21/6 – 5/6 log2 5/6 = 0.65
Entropy (Medium)=-2/5 log2 2/5 – 3/5 log2 3/5 = 0.97
Entropy (Large) = -2/4 log22/4 -2/4 log2 2/4=1
Gain (S, Engine) =0.7232-6/15*0.65-5/15*0.97-4/15*1 = -0.1268
Values( SC/Turbo)=[Yes,NO]
Syes [2+,2-]
SNO[3+,8-]
Entropy(Syes)=-2/4 log22/4 -2/4log22/4=1
Entropy(SNO)=-3/11log23/11-8/11log28/11=0.8453
Gain(S, SC/Turbo)=Entropy(S)-4/15 En(Syes) -11/15 En (Sno) = 0.7232-4/15*1-11/15*0.8453=
-0.163
Values(Weight)=[average , light , heavy ]
Saverage [3+,3-]
Slight [1+,3-]
Sheavy [1+,4-]
Entropy(Saverage)=-3/6log23/6-3/6log23/6 =1
Entropy(Slight)=-1/4log21/4-3/4log23/4=0.811
Entropy(Sheavy)= -1/5log21/5-4/5log24/5=0.721
Gain(S,Weight)=Entropy(S)-6/15En(Saverage)-4/15 Entropy(Slight)-5/15 Entropy(Sheavy)
=0.7232-6/15*-4/15*0.811-5/15*0.721=-0.1334
Values(Fuel Eco)=[Good,avarge,bad]
Sgood [0+,2-]
Savarge [0+,3-]
Sbad [5+,5-]
Entropy(Sgood)=0-2/2log22/2=0
Entropy(Savarge) =0
Entropy(Sgood)= -5/10log25/10 -5/10log25/10=1
Gain(S, Fuel Eco)=Entropy(S) - 2/15En(Sgood)-3/15 Entropy(Saverage)-10/15 Entropy(Sbad)
=0.7232-2/15*0-3/15*0-10/15*1= 0.056
So, according to the information Gain measure, the Fuel Eco attribute provide the best
prediction the output attribute fast,
Root Node Fuel ECO
Q2. Apply the Alpha Beta Pruning Algorithm on the Following given tree?
Answer:
Q4. Consider the below given iris data set. This dataset contains 3 classes of 15 instances each
and each class refers to a type of iris plant. The dataset has two features: sepal length, sepal
width. The third column is for species, which holds the value for these types of plants. A new
plant is identified. You have to classify the Species class of new identified plant with the help
of KNN algorithm and K= 3.
Answer:
First Step to find the Euclidean distance between the Observed and actual length and width
X =Observed Sepal length =5.2
Y= Observed Sepal width = 3.1
A= Actual Sepal length =5.3
B= Actual Sepal width =3.7
_________
Distance =√(𝒙 − 𝒂)𝟐 + (𝒚 − 𝒃)𝟐
_____________
=√(𝟓. 𝟐 − 𝟓. 𝟑)𝟐 + (𝟑. 𝟏 − 𝟑. 𝟕)𝟐 = 0.608
Sepal length Sepal width species Distance
5.3 3.7 setosa 0.608
Now for second row
_________
Distance =√(𝒙 − 𝒂)𝟐 + (𝒚 − 𝒃)𝟐
______________
=√(𝟓. 𝟐 − 𝟓. 𝟏)𝟐 + (𝟑. 𝟏 − 𝟑. 𝟖)𝟐 = 0.707
Dis for third row Now for distance for all rows and the table is as follow
Sepal length Sepal Width Species Distance Rank
5.3 3.7 Setosa 0.608 3
5.1 3.8 Setosa 0.707 6
7.2 3.0 Virginiea 2.002 13
5.4 3.4 Setosa 0.36 2
5.1 3.3 Setosa 0.22 1
5.4 3.9 Setosa 0.82 8
7.4 2.8 Virginiea 2.22 15
6.1 2.8 Virginiea 0.94 10
7.3 2.9 Virginiea 2.1 14
6.0 2.7 Virginiea 0.89 9
5.8 2.8 Virginiea 0.69 5
6.3 2.3 Verscicolor 1.36 12
5.1 2.5 Verscicolor 0.60 4
6.3 2.5 Verscicolor 1.25 11
5.5 2.4 Verscicolor 0.75 7
For K =1
For k=3
Here
NO of Setosa are =3
No of verscicolor are =0
No of virginica are=0
So majority is Setosa
Final Answer
Q3. By using single layer perceptron algorithm classify the following patterns. Where X1
and X2 are inputs Y is the output. Learning rate is 0.5 , output is 1 if weighted sum >=0.5
otherwise 0 and weights w1 =0.2 and w2 = 0.3
X1 X2 Y
0 0 0
0 1 1
1 0 1
1 1 1
Answer:
For case 3 X1 = 1 , X2 = 0
W1 X1 + W2 X2 = 0.2x1 + 0.7x0
W1 X1 + W2 X2 = 0.2
F(W1 X1 + W2 X2 ) = f(0.2) = 0
but actual output is 1.
dԐ dԐ
For W1 = W1 .α. W 2 = W 2 ..
𝑑W1 𝑑W2
dԐ dԐ
= X1 + (Error) = X2 + (Error)
𝑑W1 𝑑W2
W1 = W1 – α. X1 (0 – 1) W2 = W2 – α . 0 (0 – 1)
W1 = W1 – (0.5). 1 (– 1) W 2 = W2
W1 = W1 – (0.5)(– 1)
W1 = W1 + 0.5
W2 = 0.3
Case 1:-
Case 2:-
Case 3:-
Case 4:-
W1 = 0.7
W2 = 0.3