CIE-2 Solutions
CIE-2 Solutions
Machine Learning
(U21PC602CS)
B.E (CSE) V-Semester (CIE-2) Solutions
Author:
B. Venkataramana
Assistant Professor
1.Define Policy and Reward.
A policy is a strategy used by an agent to determine the next action based on the
current state. It can be represented as a function π that maps states to probabilities
of selecting each possible action.
π(a|s) = P (At = a | St = s)
Where:
• π(a|s) is the probability that action a is taken when the state is s.
• At is the action taken at time step t.
• St is the state at time step t.
A reward is a scalar feedback signal given to an agent to indicate how well it is
performing at a particular task. The reward function R maps each state or state-action
pair to a real number.
R:S ×A→R
Where:
• S is the set of all possible states.
• A is the set of all possible actions.
• R(s, a) is the reward received after taking action a in state s.
2.List the activation functions commonly used in neural network.
1
σ(x) =
1 + e−x
exi
Softmax(xi ) = P xj
je
3.Assign the point (5,2) to a cluster where centroids of each cluster are
A : (4,6) B: (1,5) C: (7,2)
Given:
2
• Point P : (5, 2)
• Centroids:
– A : (4, 6)
– B : (1, 5)
– C : (7, 2)
The Euclidean distance d between two points (x1 , y1 ) and (x2 , y2 ) is given by:
p
d= (x2 − x1 )2 + (y2 − y1 )2
p
d(P, A) = (4 − 5)2 + (6 − 2)2
p
= (−1)2 + 42
√
= 1 + 16
√
= 17
≈ 4.12
p
d(P, B) = (1 − 5)2 + (5 − 2)2
p
= (−4)2 + 32
√
= 16 + 9
√
= 25
=5
p
d(P, C) = (7 − 5)2 + (2 − 2)2
p
= 22 + 02
√
= 4
=2
3
2(a). Build a simple linear regression for the following data X 2 5 3 4
Y 7 14 8 9
Given data:
X : {2, 5, 3, 4}
Y : {7, 14, 8, 9}
Y = 1.8 + 2.2X
k
X
H(Y ) = − pi log2 (pi )
i=1
4
where pi is the probability of class i.
For the given dataset:
2 2 2 2
H(Y ) = − log2 + log2 =1
4 4 4 4
5
X1
0 1
0 0 1 1
Metric Formula
1 Pn
Mean Absolute Error (MAE) MAE = n i=1 |yi − ŷi |
1 Pn
Mean Squared Error (MSE) MSE = n i=1 (yi − ŷi )2
√
Root Mean Squared Error (RMSE) RMSE = MSE
Pn
(yi −ŷi )2
R-squared (R2) R2 = 1 − Pi=1
n 2
i=1 (yi −ȳ)
6
Table 2 Confusion Matrix
False Positives (FP): The cases in which the model incorrectly predicts the positive
class.
True Negatives (TN): The cases in which the model correctly predicts the negative
class.
False Negatives (FN): The cases in which the model incorrectly predicts the
negative class.
Metric Formula
TP + TN
Accuracy
TP + TN + FP + FN
FP + FN
Error Rate
TP + TN + FP + FN
TP
Precision
TP + FP
TP
Recall (Sensitivity)
TP + FN
TN
Specificity
TN + FP
Precision × Recall
F1 Score 2×
Precision + Recall
z = w1 x1 + w2 x2 + · · · + wn xn + b
(
1 if z ≥ 0
y=
0 if z < 0
Training
7
Training involves adjusting the weights and bias based on errors:
• Initialize weights and bias randomly.
• Update weights and bias using the following rules if there is a misclassification:
b ← b + η(yi − ŷi )
where η is the learning rate.
• Repeat for a fixed number of epochs or until convergence.
Applications
• Binary Classification
• Linearly Separable Problems
Limitations
• Cannot solve non-linearly separable problems (e.g., XOR problem).
• Limited to single-layer models.
4.(a)Use single link agglomerative clustering to group the given data
with the following distance matrix and show a dendrogram
A B C D
A 0 1 4 5
B 1 0 2 6
C 4 2 0 3
D 5 6 3 0
Steps and Dendrogram
1. Initial Clusters: {A}, {B}, {C}, {D}
2. First Merge:
• The closest pair is {A, B} with distance 1.
• Merge A and B into a new cluster {A, B}.
3. Update Distance Matrix:
{A, B} C D
{A, B} 0 2 5
C 2 0 3
D 5 3 0
4. Second Merge:
• The closest pair is {C, D} with distance 3.
• Merge C and D into a new cluster {C, D}.
8
5. Update Distance Matrix:
{A, B} {C, D}
{A, B} 0
{C, D} 2
6. Final Merge:
• The remaining clusters {A, B} and {C, D} are merged with distance 2.
Dendrogram
B A, B C, D
A 1 C 2 D 5 A, B, C, D
9
1. Expectation Step (E-Step): Compute the probability that each data point
belongs to each cluster, given the current parameters:
πk N (xi | µk , Σk )
γik = PK
j=1 πj N (xi | µj , Σj )
10