Docsity

CMPS 242 Homework: Decision Trees, Perceptron Algorithm and Logistic Regression, Assignments of Computer Science

Toggle sidebar
bg1
CMPS 242 Second Homework, Winter 2009
3 Problems, due start of class Tuesday Feb. 3
This homework in to be done in groups of 2-3. Each group members should completely
understand the group’s solutions and must acknowledge all sources of inspiration, techniques,
and/or helpful ideas (web, people, books, etc.) other than the instructor and class text.
1. Construct a small data set with boolean features where the greedy (univariate) decision
tree procedure using the impurity heuristic (Equation 9.8 in Alpaydin) fails to find a
smallest decision tree. Show the optimal tree as well as the tree resulting from the
greedy top-down construction procedure. (Hint: my solution has three features, and
the optimal tree uses two of them. You may repeat examples in the training set)
2. Perceptron algorithm. Implement the Perceptron algorithm presented in class in 2
dimensions and perform the following experiments where concept Cis defined by
C(x) = +1 if x1+x2>0 and C(x) = −1 otherwise.
Experiment 1:
Generate a 10 example training set by picking points uniformly at random
from the unit circle and generating labels (y-values) according to C.
Calculate the gap of the best homogeneous separating line (this gap is the
distance between the separating line and the closest example, and the best
separating line is not likely to be C’s decision boundary).
Run the Perceptron algorithm and note how many ”mistakes” it makes before
finding a consistent hypothesis, and how many iterations through the data
are required before it finds a consistent hypotheses.
Perform experiment 1 ten times and sort them by the gap. Do you see a relationship
between the gaps and the number of iterations of number of mistakes made?
Experiment 2:
Generate a 100 example training set by picking points uniformly at random
from the unit circle, with noisy labels. For each example x= (x1, x2) in the
training set, generate a random number rin [0,1]. If x1+x2+ 2r−1>0
then set the label of xto 1. If x1+x2+ 2r−1≤0 then set the label of x
to −1. Also generate two 100 example test sets, one the same way and one
without noise.
This generates a noisy version of Cwhere the noise tends to be concentrated around
the decision boundary.
Run the following version of the perceptron algorithm for 500 iterations where each
iteration uses a random point from the training set (rather than cycling through the
training set) and save the weight vector wiafter each iteration i. Compare how well
the following prediction rules perform on the test sets.
pf2

Partial preview of the text

Download CMPS 242 Homework: Decision Trees, Perceptron Algorithm and Logistic Regression and more Assignments Computer Science in PDF only on Docsity!

CMPS 242 Second Homework, Winter 2009 3 Problems, due start of class Tuesday Feb. 3 This homework in to be done in groups of 2-3. Each group members should completely understand the group’s solutions and must acknowledge all sources of inspiration, techniques, and/or helpful ideas (web, people, books, etc.) other than the instructor and class text.

  1. Construct a small data set with boolean features where the greedy (univariate) decision tree procedure using the impurity heuristic (Equation 9.8 in Alpaydin) fails to find a smallest decision tree. Show the optimal tree as well as the tree resulting from the greedy top-down construction procedure. (Hint: my solution has three features, and the optimal tree uses two of them. You may repeat examples in the training set)
  2. Perceptron algorithm. Implement the Perceptron algorithm presented in class in 2 dimensions and perform the following experiments where concept C is defined by C(x) = +1 if x 1 + x 2 > 0 and C(x) = −1 otherwise. Experiment 1:

Generate a 10 example training set by picking points uniformly at random from the unit circle and generating labels (y-values) according to C. Calculate the gap of the best homogeneous separating line (this gap is the distance between the separating line and the closest example, and the best separating line is not likely to be C’s decision boundary). Run the Perceptron algorithm and note how many ”mistakes” it makes before finding a consistent hypothesis, and how many iterations through the data are required before it finds a consistent hypotheses.

Perform experiment 1 ten times and sort them by the gap. Do you see a relationship between the gaps and the number of iterations of number of mistakes made? Experiment 2:

Generate a 100 example training set by picking points uniformly at random from the unit circle, with noisy labels. For each example x = (x 1 , x 2 ) in the training set, generate a random number r in [0, 1]. If x 1 + x 2 + 2r − 1 > 0 then set the label of x to 1. If x 1 + x 2 + 2r − 1 ≤ 0 then set the label of x to −1. Also generate two 100 example test sets, one the same way and one without noise.

This generates a noisy version of C where the noise tends to be concentrated around the decision boundary. Run the following version of the perceptron algorithm for 500 iterations where each iteration uses a random point from the training set (rather than cycling through the training set) and save the weight vector wi after each iteration i. Compare how well the following prediction rules perform on the test sets.

(a) Last hypothesis: predict on x with sign(w 500 · x), using the hypotheses from the last iteration. (b) Voted hypothesis: predict on x using the majority of the wi, i.e. sign

(∑ 500 i=1 sign(wi^ ·^ x)

) . (c) Longest survivor: Each w values is created on some iteration t, predicts correctly for a while, and then makes a mistake at some later iteration t′. The survival time of w is t′^ − t. Let w` be the longest surviving hypothesis from the 500 iterations (pick the first one in case of ties, and assume that the last w makes an incorrect prediction on iteration 501).

Create 10 different training and testing sets, and run the perceptron algorithm on each training set. How well do each of the three prediction rules do on the test sets?

  1. Logistic regression used the logistic sigmoid function to give the class probabilities of an example x with the weight vector w:

probability x has class 1 = p 1 (x|w) =

exp w · x 1 + exp w · x

and p 0 (x|w) = 1 − p 1 (x|w). Show that this is equivalent to w · x giving the log-odds:

ln

p 1 (x|w) p 0 (x|w)

= w · x.

Recommended exercises (not to be turned in):

  • Make up a small dataset (say 8 examples with three boolean features) and compute the impurity (Equation 9.8) after each of the possible splits.
  • Use Weka to learn a decision tree, neural network, and an SVM (Using the SMO algorithm) from the Iris2 dataset. It is also interesting to try training a simple XOR dataset (where y = x 1 ⊕x 2 ) with a neural network and seeing how slow the convergence is (especially when there are additional irrelevant features).
  • Given one dimensional Gaussian distributions P (x|+) and P (x|−) having the same σ but different means, find the decision boundary minimizing the probability of a mistake when P (+) = 2P (−). Next, find the Bayes optimal decision boundary when the cost of a false positive is twice the cost of a false negative (and the cost of a correct prediction is 0).
  • Dig out your (old?) linear algebra book and verify that equation (10.49) uses the Lagrange multipliers correctly. Also verify that the dual (10.52) is correctly formulated.