Homework 2
Homework 2
Homework 2
Jason J. Corso
TAs: Shujie Liu and Suxin Guo
Computer Science and Engineering
SUNY at Buffalo
jcorso@buffalo.edu
Date Assigned 20 March 2012
Date Due 19 April 2012
Homework must be submitted by midnight of the due-date, electronically (see below). No late work will be accepted.
Remember, you are permitted to discuss this assignment with other students in the class (and not in the class), but
you must write up your own work from scratch.
I am sure the answers to some or all of these questions can be found on the internet. Copying from any another
source is indeed cheating. Obviously, it will undermine the primary purpose you are taking this course: to learn.
This class has a zero tolerance policy toward cheaters and cheating. Dont do it.
Pn
i=1 xi .
m (1 )n d =
m!n!
,
(m + n + 1)!
(n + 1)! s
(1 i )ns .
s!(n s)! i
3. Using Bayes parameter estimation of p(|D), integrate the product P (x|)p(|D) over to obtain the desired
conditional probability
p(x|D) =
s+1
n+2
x
s + 1 1x
1
n+2
4. If we use maximum likelihood estimation to estimate , what is the estimated p(x|D)? What is the difference
between maximum likelihood estimation result and Bayesian estimation result?
Problem 2: Nonparametric Methods (25%)
This is problem 6 in DHS Chapter 4.
Let D = {x1 , . . . , xn } be a set of n independent labeled samples and let Dk (x) = {x01 , . . . , x0k } be the k nearest
neighbors of x. Recall that the k-nearest-neighbor rule for classifying x is to give x the label most frequently
1
represented in Dk (x). Consider a two-category problem with P (1 ) = P (1 ) = 1/2. Assume further that the
conditional densities p(x|i ) are uniform within unit hyperspheres a distance of ten units apart.
1. Show that if k is odd, the average probability of error is given by
(k1)/2
n
1 X
Pn (e) = n
2
j
(1)
j=0
2. Show that for this case the single-nearest neighbor rule has a lower error rate than the k-nearest-neighbor error
rate for k > 1.
2. (40%) On the to linear no-slack SVM in hw2 svm.py. This code follows the Burges formulation. You are
required to implement the missing parts of the code as specified in the file. The missing parts implement the
elements of the quadratic program that is the base of the SVM as well as the ultimate solution for the weight
vector, bias, and the margin. You need to implement all of them.
Once done, you should run hw2 svm.py (make sure your PYTHONPATH and LD LIBRARY PATH are set
properly). This will test the linear SVM on three data sets. It will also save figure outputs for all three. Submit
the text output and the figure outputs.
Provide an explanation of the outputs, the weight vector, bias term, and margin for all three cases. Pay specific
attention to the uniqueness of the third data set over the first two. What is special about the third one? What
would we need to do to handle this case?
You need to submit the following:
(a) The completed hw2 svm.py file. (We will run this separately with different data.)
(b) A short description of how you implemented the missing elements from the file. I.e., how did you
implement the constraints.
(c) The output from running the script and the explanation required above.
In addition to these requirements, you are encouraged to implement the necessary changes to solve the third
data set.