Assignment-2 ML
Assignment-2 ML
1. We have 2 opaque bags, each containing 2 balls. One bag has 2 black balls and the other has a black
and a white ball. You pick a bag at random and then pick one of the balls in that bag at random. When
you look at the ball it is black. You now pick the second ball from that same bag. What is the probability
that this ball is also black?
Hint: Use Bayes’ Theorem: 𝑃𝑃[𝐴𝐴 𝑎𝑎𝑎𝑎𝑎𝑎 𝐵𝐵] = 𝑃𝑃[𝐴𝐴|𝐵𝐵]𝑃𝑃[𝐵𝐵] = 𝑃𝑃[𝐵𝐵|𝐴𝐴]𝑃𝑃[𝐴𝐴]
2. Let us create our own target function 𝑓𝑓 and data set 𝐷𝐷 and see how the perceptron learning algorithm
works. Take 𝑑𝑑 = 2 so you can visualize the problem and choose a random line in the plane as your
target function, where one side of the line maps to +1 and the other maps to −1. Choose the inputs
𝑥𝑥𝑛𝑛 of the data set as random points in the plane and evaluate the target function on each 𝑥𝑥𝑛𝑛 to get the
corresponding output 𝑦𝑦𝑛𝑛 . Now, generate a data set of size 20. Try the perceptron learning algorithm
on your data set and see how long it takes to converge and how well the final hypothesis 𝑔𝑔 matches
your target 𝑓𝑓.
3. Let’s further explore perceptron learning algorithm with data sets of different sizes and dimensions.
a. Generate a linearly separable data set of size 20 as done in above problem 2. Plot the examples
{(𝑥𝑥𝑛𝑛 , 𝑦𝑦𝑛𝑛 )} as well as the target function 𝑓𝑓 on a plane. Be sure to mark the examples from different
classes differently and add labels to the axes of the plot.
b. Run the perceptron learning algorithm on the data set above. Report the number of updates that
the algorithm takes before converging. Plot the examples {(𝑥𝑥𝑛𝑛 , 𝑦𝑦𝑛𝑛 )}, the target function 𝑓𝑓, and the
final hypothesis 𝑔𝑔 in the same figure. Comment on whether 𝑓𝑓 is close to 𝑔𝑔.
c. Repeat everything in (b) with another randomly generated data set of size 20. Compare your
results with (b).
d. Repeat everything in (b) with another randomly generated data set of size 100. Compare your
results with (b).
e. Repeat everything in (b) with another randomly generated data set of size 1,000. Compare your
results with (b).
f. Modify the algorithm such that it takes 𝑥𝑥𝑛𝑛 ∈ ℝ10 instead of ℝ2 . Randomly generate a linearly
separable data set of size 1,000 with 𝑥𝑥𝑛𝑛 ∈ ℝ10 and feed the data set to the algorithm. How many
updates does the algorithm take to converge? To generate the data essentially randomly take a
10-dimensional hyperplane equation first and then randomly generate datapoints and assign
labels to it.
g. Repeat the algorithm on the same data set as (f) for 100 experiments. In the iterations of each
experiment, pick x(t) randomly instead of deterministically. Plot a histogram for the number of
updates that the algorithm takes to converge.
h. Summarize your conclusions with respect to accuracy and running time as a function of N and d.
You have to create a 1–2-page report answering all the parts above and submit as a pdf file. Also submit
a Jupyter notebook as a separate file.
Naming conventions for files:
<enrolmentNo>_<name>.pdf
<enrolmentNo>_<name>.ipynb