ML Soln 2
ML Soln 2
Instructions: (I) You must submit a copy of your own handwritten homework (except
for the coding portion, no computer-typed submission will be accepted). Further, copying
homework from your friends is forbidden. If found copied, the homework submission will be
considered invalid for all the students involved and will be graded zero. (II) Write all the
steps, including your reasoning and the formulae you referred to, if any. While submitting
codes, make sure the code is running and you must submit a report of the plots and results
in a PDF, along with your observations. Submit all the scanned copies in a ZIP file named
“HW1 Name EntryNumber”.
where A and D are square matrices, and assuming that D and A − BD−1 C are
invertible:
(a) Derive the inverse of M and show that:
(A − BD−1 C)−1 −A−1 B(D − CA−1 B)−1
M−1 =
−D−1 C(A − BD−1 C)−1 (D − CA−1 B)−1
1
APL 744, Homework 1
(A) Consider two random variables x and y with joint distribution p(x, y). You have to
prove the following two results:
(i) Expectation:
h i
E[x] = Ey Ex [x|y]
(ii) Variance:
h i h i
var[x] = Ey varx [x|y] + vary Ex [x|y] .
Here Ex [x|y] denotes the expectation of x under the conditional distribution p(x|y),
with a similar notation for the conditional variance.
(B) In the following question you have to use MCMC sampling for the following two
problems:
(i) Write a small code that uses random numbers to approximate the value of π.
(ii) Besides simulating random processes, the random numbers can also be used for
evaluating integrals. Write computer programs to approximate the following
integrals and compare your estimate with the exact answers. (For exact answers,
you are allowed to use inbuilt functions.)
R 1 ex R∞ R 1 R 1 (x+y)2
(i) 0 e dx, (ii) 0 x(1 + x2 )−2 dx, (iii) 0 0 e dxdy.
(A) Prove that the convolution of two Gaussian distributions is a Gaussian distribution.
Write a computer code to verify your results. [Marks: 5]
(B) Given the following bivariate distribution, [Marks: 5]
xa σ2 ρσa σb
p(x | µ, Σ) = N , a
xb ρσa σb σb2
(ρσa σb )2
!
ρσa σb 2
p(xa | xb ) = N xa | µa + (x b − µ b ), σa −
σb2 σb2
Question 5. Design and Implementation of Decision Trees with Custom Splitting Criteria
[Total Marks: 25]
You are tasked with designing a decision tree algorithm with support for custom splitting
criteria. Consider the following tasks:
and
X |Tv |
Information Gain, Ig = E(Parent Node) − E(Tv ),
v∈values |T |
where Tv represents the subset of data for a specific value of the splitting feature and
values represents the unique values or splits of the feature being considered.
Initially set wj = 1 (uniform weights). Later, adjust wj based on the variance of feature j,
assigning higher weights to features with lower variance.
2. Compare the performance of this weighted Euclidean distance metric with the standard
Euclidean distance on the validation set.
Part C: Hyperparameter Tuning
1. Optimize the number of neighbors k using the validation set. Experiment with k ∈
{1, 3, 5, 10, 15}.
2. Compare the performance of different distance metrics, Standard Euclidean distance,
Manhattan distance and Weighted Euclidean distance (from Part B).
Part D: Weighted Voting
1. Implement a weighted voting mechanism where the weight of each neighbor is inversely
proportional to its distance:
1
wi = .
1 + d(x, xi )
2. Analyze the impact of weighted voting on the overall performance metrics, including:
• Accuracy.
• Confusion Matrix.
Part E: Model Evaluation
1. Evaluate the final model with the optimal k and distance metric on the test set.
2. Analyze and report:
• Overall accuracy.
• Class-specific performance to detect any biases.