KDAG Task
KDAG Task
Round II
There is a single task with four sub-tasks. It is not mandatory to solve all the sub-tasks. Solve as many as
you can. If you are not comfortable with coding, just give it a try. That will also fetch you some points. We
would like to see how you approach the problem and how organized your presentation of thoughts is. For
mathematical solution, you are required to upload a scanned pdf of your handwritten solution. You
may also type the solution in MS Word or Latex whichever is preferred. For coding, you are required
to submit the python files. Name the python file for subtask-2 as {your roll no subtask2.py} and for
subtask-4 as {your roll no subtask4.py}. Make sure to write how you read the data at the beginning
of your code. It will be better if you keep a path variable for loading the data which will make our
evaluation easier.
• data/ds1 train,test.csv
• data/ds2 train,test.csv
Link to Dataset
Each file contains m examples, one example (x(i) , y (i) ) per row. In particular, the ith row contains columns
(i) (i)
x0 ∈ R, x1 ∈ R, and y (i) ∈ {0, 1}. In the sub-tasks that follow, perform Logistic Regression and Gaussian
Discriminant Analysis on these two datasets.
Problem: Find the Hessian matrix H of the empirical loss function with respect to θ, and show that the hessian
H is positive semi-definite in nature.
1
Third Subtask: 20 points
For Gaussian Discriminant Analysis, the joint probability distribution of (x, y) is given by the following
equations:
φ if y = 1
p(y) =
1 − φ if y = 0
1 1
T −1
p(x|y = 0) = exp − (x − µ0 ) Σ (x − µ0 )
(2π)n/2 |Σ|1/2 2
1 1 T −1
p(x|y = 1) = exp − (x − µ1 ) Σ (x − µ1 )
(2π)n/2 |Σ|1/2 2
where φ, µ0 , µ1 , and Σ are the parameters of the model.
Let us assume that φ, µ0 , µ1 , and Σ are already found using some mathematical manipulation, and now we
want to predict y given a new point x. In order to show that Gaussian Discriminant Analysis results in a
classifier that has a linear decision boundary, show that the following expression is true.
1
p(y = 1|x; φ, µ0 , µ1 , Σ) =
1 + exp(−(θT x + θ0 ))
where θ ∈ Rn and θ0 ∈ R are appropriate functions of φ, µ0 , µ1 , and Σ.
Hint: Use Bayes theorem in order to get the above probability and with some mathematical manipu-
lation on the expression obtained using Bayes Rule, try to express it in the form shown in the Right
Hand Side, ultimately comparing the expressions, you will obtain the required result.
Using the results mentioned above, write code to find the values of the parameters. Finally, find the probability
of each of the training and test examples using the expression of probability that you had to prove given in the
previous sub-task (expression resembling sigmoid function). Note that you have already obtained θ and θ0 in
terms of the parameters φ, µ0 , µ1 and Σ. After you find the probabilities for the training and testing examples,
mark a probability greater than or equal to 0.5 as 1 and a probability less than 0.5 as 0. Finally, print the
accuracy of training set and test set for both the datasets.