Docsity

Non-Linear Models - Homework #2 - Machine Learning | CS 5350, Assignments of Computer Science

Toggle sidebar
bg1
Machine Learning (CS 5350/CS 6350) Due 15 Feb 2007
HW2: Non-linear models
Note: Please submit the written aspects of assignments in postscript or PDF format only. I highly recom-
mend you use L
A
T
EX to prepare the assignments. A solution will be posted here after the due date. See
http://www.cs.utah.edu/classes/cs5350/handin.html for handin instructions.
1 PRML Exercises
Complete the following exercise from PRML: 14.11 (only for entropy, not for Gini index).
Bonus: 14.8.
2 Written Exercises
1. Suppose you have data that is linearly separable. Compare and contrast the potential results of running
a linear algorithm (like an SVM) and running kNN.
2. Other than information gain, what might be a reasonable metric for finding ā€œgood featuresā€ for a
decision tree? What advantages/disadvantages does your proposal have compared to IG?
3. Using Mercer’s condition, verify that the sum of two kernels is still a kernel and that a kernel times a
positive real is still a kernel (i.e., examples 1 and 2 under ā€œBuilding kernelsā€ in notes07).
4. What are the three components of a reduction? Specify them for the cases of costing and weighted-
all-pairs.
5. CS6350 Only: How does costing relate to bagging?
3 Programming
There are two parts to the programming part for this assignment. The first part involves implemented a
k-nearest-neighbor classifier (CS6350 students have a little additional work here). The second part involves
downloading and running other people’s software to get familiar with standard software/data-formats.
Part I:
Implement a k-nearest neighbor classifier, with kas a parameter. Apply this classifier to both the data set
from homework 1 as well as the new data set for this assignment (the new data set is a multiclass classification
data set, so your implementation will need to accomodate this).
Allow kto range over all integers in [1,20] and plot development and test error as a function of k. At which
value of kis development error minimized? At which value of kis test error minimized? Rerun the averaged
perceptron on both data sets (you can either use your implementation or mine) and find the iteration at
which the development error is minimized. Look at the test error on this iteration. How does this compare
to the kNN performance? Which model would you choose to use on these two data sets? You should hand
in error plots for kNN and for the perceptron, together with answers to the questions from this paragraph.
Part II:
In this part, we will experiment using other people’s software, so the programming aspect of this part will
just be to write some short scripts for converting data formats. The two software packages we will use are
1
pf2

Partial preview of the text

Download Non-Linear Models - Homework #2 - Machine Learning | CS 5350 and more Assignments Computer Science in PDF only on Docsity!

Machine Learning (CS 5350/CS 6350) Due 15 Feb 2007

HW2: Non-linear models

Note: Please submit the written aspects of assignments in postscript or PDF format only. I highly recom- mend you use LATEX to prepare the assignments. A solution will be posted here after the due date. See http://www.cs.utah.edu/classes/cs5350/handin.html for handin instructions.

1 PRML Exercises

Complete the following exercise from PRML: 14.11 (only for entropy, not for Gini index).

Bonus: 14.8.

2 Written Exercises

  1. Suppose you have data that is linearly separable. Compare and contrast the potential results of running a linear algorithm (like an SVM) and running kNN.
  2. Other than information gain, what might be a reasonable metric for finding ā€œgood featuresā€ for a decision tree? What advantages/disadvantages does your proposal have compared to IG?
  3. Using Mercer’s condition, verify that the sum of two kernels is still a kernel and that a kernel times a positive real is still a kernel (i.e., examples 1 and 2 under ā€œBuilding kernelsā€ in notes07).
  4. What are the three components of a reduction? Specify them for the cases of costing and weighted- all-pairs.
  5. CS6350 Only: How does costing relate to bagging?

3 Programming

There are two parts to the programming part for this assignment. The first part involves implemented a k-nearest-neighbor classifier (CS6350 students have a little additional work here). The second part involves downloading and running other people’s software to get familiar with standard software/data-formats.

Part I:

Implement a k-nearest neighbor classifier, with k as a parameter. Apply this classifier to both the data set from homework 1 as well as the new data set for this assignment (the new data set is a multiclass classification data set, so your implementation will need to accomodate this).

Allow k to range over all integers in [1, 20] and plot development and test error as a function of k. At which value of k is development error minimized? At which value of k is test error minimized? Rerun the averaged perceptron on both data sets (you can either use your implementation or mine) and find the iteration at which the development error is minimized. Look at the test error on this iteration. How does this compare to the kNN performance? Which model would you choose to use on these two data sets? You should hand in error plots for kNN and for the perceptron, together with answers to the questions from this paragraph.

Part II:

In this part, we will experiment using other people’s software, so the programming aspect of this part will just be to write some short scripts for converting data formats. The two software packages we will use are

HW2: Non-linear models 2

libSVM http://www.csie.ntu.edu.tw/~cjlin/libsvm/ (which, not surprisingly, implements support vector machines) and FastDT http://hal3.name/FastDT (a decision tree implementation). You can either download and install these yourself, or you can use the version I have installed on CADE (in ~cs5350/bin, the libSVM executables are svm-train and svm-predict, while the FastDT executable is FastDT).

The libSVM file format is one-example-per-line. The first column is the class (for binary this should be āˆ’ 1 or 1; for multiclass this should be a number 0, 1 , 2 ,... ). The remaining columns have format D:N , where D is a feature number and N is the feature value. I.e., our matlab format might have a row like:

The corresponding libSVM line would be something like:

Note that we could exclude feature 5 because its value was zero. The features must appear sorted.

Using the same data set as from HW1, train the following SVMs (using just the training data): a linear SVM, a quadratic SVM, a cubic SVM and an RBF SVM. For each, try different values of C ranging in

  1. 25 , 0. 5 , 1 , 2 , 4. For the RBF SVM, try γ values of 0. 25 , 0. 5 , 1 , 2 , 4. Plot error rates on both the development data and test data for the different values of C. How many support vectors are used for each model? Should this increase or decrease with C (why?)?

CS6350 Students only... (the following is bonus for CS5350)

Now, play around with FastDT. This software only allows binary problems (this is fine) but also only allows binary features! The format for a single example is:

class f1 f2 f5 f

Here, class should be either 0 or 1. The existence of f1,f2,f5,f7 means that these five features have value 1; any feature that doesn’t appear is assumed to have value zero.

You will need to convert the real-valued features from the data sets to binary features. In order to do this, first normalize each feature so that it only has range [0, 1] on the training data (note that it may still be outside this range on the development or test data). Replace each real-valued feature with eight binary features: is the value above/below 0.2, above/below 0.4, 0.6, or 0.8. The features can be any strings. Suppose that after normalization, the example from above were something like āˆ’1ā€œ0.2ā€œ0.75ā€œ0.1ā€œ0.9ā€œ0.6. Then, the FastDT input might look something like:

0 f1>=0.2 f1<0.4 f1<0.6 f1<0.8 f2>=0.2 f2>=0.4 f2>=0.6 f2<0. f3<0.2 f3<0.4 f3<0.5 f3<0.8 f4>=0.2 f4>=0.4 f4>=0.6 f4>=0. f5>=0.2 f5>=0.4 f5>=0.6 f5<0.

(But obviously without the line breaks.)

Now, train four decision trees, each with a different maximum tree depth (command line option -maxd). Use depths 5, 10, 15 and 20. Compare the performance of this on develoment and test data. Between the SVMs and the decision tree, which tends to perform best overall?