• Ei tuloksia

582631 Introduction to Machine Learning, Autumn 2015 Exercise set 3 (based on second week of lectures)

N/A
N/A
Info
Lataa
Protected

Academic year: 2022

Jaa "582631 Introduction to Machine Learning, Autumn 2015 Exercise set 3 (based on second week of lectures)"

Copied!
3
0
0

Kokoteksti

(1)

582631 Introduction to Machine Learning, Autumn 2015 Exercise set 3 (based on second week of lectures)

To be discussed in the exercise session 12 November. Attending the session is completely voluntary.

Credit is given based on the written solutions turned in to the course assistants.

The deadline for turning in your solutions isFriday, 13 November, at 23:59.

Follow the provided guidelines and send your solutions to the course assistants (johannes.verwijnen@cs.helsinki.fi) and (amin.sorkhei@cs.helsinki.fi) by e-mail.

Submission Guidelines

(1) Your submission is composed of two parts:

• A single PDF file containing you answer to pen and paper and programming problems and a single compressed file (either rar, zip, tar.gz) containing your code. The submission must be sent directly to BOTHJohannes and Amin. If you are not using Python, please mention in your email what programming language you have used. In that case, the code needs to be submitted as a runnable file or set of files (command to run it given in the report).

• All the material (compressed file, code, PDF file) must be renamed to your student ID.

(2) If you are using Python, please use the provided scaffolding (https://github.com/amin-sorkhei/IML-req/

blob/master/ASSG3_TMP.py) in order to do the programming assignment and only submit the completed scaffolding as your code. You have to implementsimple EC classifierandKNNmethods. DO NOT include any of the data files (MovieLens, MNIST) in your email.

(3) Always mention your name and student ID in the report.

(4) Use the tag [IML15][your student ID] as the subject of your email.

Pen-and-paper problems

Problem 1 (3 points)

Consider a binary classification task with two classes, ‘+’ and ‘–’. The desired prediction is either one of the two classes, or alternatively answering ‘don’t know’, with the following cost matrix:

predicted class

actual class +

+ –

$0 $4

$8 $0

don’t know

$1

$1

$0

$0

$3

$10 $2

$1

The goal is to minimize the expected cost (which is also the long-term average cost). You are given a classifica- tion method that returns a probabilistic prediction, i.e. for each new object the existing method gives you the probabilityαthat the object belongs to class ‘+’ (and hence 1−αis the probability that the object belongs to class ‘-’).

Give the optimal policy of answering ‘+’, ‘–’, or ‘don’t know’ for each object, as a function of the value ofα.

That is, for any given value ofα(for 0≤α≤1) what is the best answer of the three possibilities?

1

(2)

Problem 2 (3 points)

In a binary classification task we are trying to classify the objectsx into classesy= 1 andy= 0. We are here using probabilistic predictions, so for each new object we are required to output our probabilityb=P(y= 1|x), with 0≤b≤1. We are using the following quadratic cost function:

C(y, b) =

(b−1)2, ify= 1

b2, ify= 0 (1)

Obviously, if the value ofy is 1, the lowest cost (0) is obtained when b = 1. Similarly, if the value of y is 0, the lowest cost (0) is obtained when b= 0, so the cost function seems to encourage appropriate behaviour. In fact, the cost function isproper. Show this.(Hint: Assume that the true probability thaty = 1 isa(so the true probability thaty= 0 is 1−a), and show that the expected cost is minimized forb=a.)

Problem 3 (3 points)

The figure below shows the class conditional probability densitiesp(x|y) whereygives one of 3 different classes (y= 0,y= 1, ory = 2) andx∈R2. Each of the class conditionals is a uniform density over the corresponding rectangle. (For example, all vectorsxbelonging to classy = 0 have attribute valuesx1∈[1,4] andx2∈[3,5], and these vectors are uniformly distributed within this rectangle.) Additionally we know that the marginal probabilities of the classes areP(y= 0) = 0.2,P(y= 1) = 0.7,P(y= 2) = 0.1. For each of the indicated points x1, . . . ,x5, compute the posterior probability distribution over the three classes. (That is, when observing a new vectorxi, what is the probability that it belongs to classy= 0, to classy= 1, or to classy= 2? Remember that these probabilities should sum to one.)

0 1 2 3 4 5 6 7

0 1 2 3 4 5 6

p(x|y= 0)

p(x|y= 1)

p(x|y= 2) x1

x2 x3

x4

x5

Computer problem

General instructions:

• In your report, the results of the programming problem will be mostly either in the form of a figure or program output. In both cases, add some sentences which explain what you are showing and why the results are the answer to the question.

• We use the report as the main basis for grading: All your results should be in the report. We also look at the code, but we won’t however go fishing for results in your code.

• If we ask you to test whether an algorithm works, always give a few examples showing that the algorithm indeed works.

Problem 4 (15 points)

In this exercise we implement an extremely simple prototype-based classifier to classify handwritten digits from the MNIST dataset, and compare that to a nearest-neighbor classifier.

(a) Download the MNIST data from the course web page. In addition to the actual data, the package contains some functions for easily loading the data into Python/Matlab/Octave/R and for displaying digits. See the README files for details. Load the first N=5,000 images using the provided function.

2

(3)

(b) Use the provided functions to plot a random sample of 100 handwritten digits, and show the associated labels. Verify that the labels match the digit images. (This is a sanity check that you have the data is in the right format.)

(c) Divide the data into two parts: A ‘training set’ consisting of the first 2,500 images (and associated labels), and a ‘test set’ containing the remaining 2,500 images (and their associated labels).

(d) For each of the ten classes (digits 0-9), compute a classprototype given by the mean of all the images in the training set that belong to this class. That is, select from the training set all images of class ‘0’ and compute the mean image of these; this should look sort of like a zero. Do this for all ten classes, and plot the resulting images. Do they look like what you would expect?

(e) For each of the images in the test set, compute the Euclidean distance of the image to all 10 prototypes, and classify the test image into the class for which the distance to the prototype is the smallest. So, if a test image is closer to the prototype for ‘3’ than it is to the prototypes for any of the other digits, predict its class to be ‘3’. Compute and display the resultingconfusion matrix.

(Hint: You need to usescipy.spatial.distance.cdistin order to calculate the similarity measure.

You need to installscipy. It would be a wise choice to go through the documentation available at:http://

docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.spatial.distance.cdist.html. In addition to this, in order to get some basic idea regarding confusion matrix you can refer tohttp:

//scikit-learn.org/stable/auto_examples/plot_confusion_matrix.html. Feel free to install and usescikit-learnin order to calculate theconfusion matrix)

(f) Classify each of the test images with a nearest neighbor classifer: For each of the test images, compute its Euclidean distance to all (2,500) of the training images, and let the predicted class be the class of the closest training image. Compute and display the resulting confusion matrix.(Use the previous hint) (g) Compute and compare the error rates of both classifiers (the prototype-based classifier and the nearest

neighbor classifier). Which is working better? Based on the confusion matrix, which digits are confused with each other? Why do you think this is?

3

Viittaukset

LIITTYVÄT TIEDOSTOT

Since both the beams have the same stiffness values, the deflection of HSS beam at room temperature is twice as that of mild steel beam (Figure 11).. With the rise of steel

Indeed, while strongly criticized by human rights organizations, the refugee deal with Turkey is seen by member states as one of the EU’s main foreign poli- cy achievements of

(f) Classify each of the test images with a nearest neighbor classifer: For each of the test images, compute its Euclidean distance to all (2,500) of the training images, and let

In this problem we will attempt to reproduce Figure 2.4 in Hastie et al (2009) 1 , also presented in the slides of lecture 6, showing the error on the test and training data as

Thus the K-medoids algorithm is exactly like the K-means algorithm (Algorithm 8.1 in the textbook, also presented in the slides for lecture 10), except that in line 4 of the

(f) Classify each of the test images with a nearest neighbor classifer: For each of the test images, compute its Euclidean distance to all (2,500) of the training images, and let

In this problem we will attempt to reproduce Figure 2.4 in Hastie et al (2009) 1 , also presented in the slides of lecture 6, showing the error on the test and training data as

You should send one PDF file including your solutions to the pen-and-paper problems and the report for the programming problem, and a single compressed file including the code for