• Ei tuloksia

582631 Introduction to Machine Learning Period II, Autumn 2015

N/A
N/A
Info
Lataa
Protected

Academic year: 2022

Jaa "582631 Introduction to Machine Learning Period II, Autumn 2015"

Copied!
2
0
0

Kokoteksti

(1)

582631 Introduction to Machine Learning Period II, Autumn 2015

Exercise #1 (Python for Machine Learning) Tuesday, 27 October, 12:15-16 in B221

(No preparation necessary, no handing-in of solutions, no points for exercises.)

Exercise 1. Generate 100 samples from a normal distribution with zero mean and unit variance.

(a) Visualize the data by drawing a histogram.

(b) Sort the data points into increasing order.

(c) Draw a line plot of points (xi, yi) fori= 1. . .100 wherexi is thei:th data point (in the sorted order) and yi is equal toi/100.

(d) Can you tell what you have drawn?

Numpy: random, sort, arange;

matplotlib.pyplot: plot;

Exercise 2. Generate a random matrix (dimensions for example 10⇥5) and store it into a file. Write a function that

• Takes a filename as an argument.

• Reads a data matrix X from the given file.

• Outputs row and column sums ofX as bar plots. Try to put both plots into the same window.

• Returns two values: the dimensions of the matrix as a vector and the sum of all elements.

Test your function by calling the function with the name of the file.

Numpy: save, load, sum;

matplotlib.pyplot: subplots, bar;

Exercise 3. The law of large numbers states that the average of a series of i.i.d. samples approaches the expectation of the generating distribution as the number of samples goes to infinity. More formally, if all xn

are i.i.d. sampled from some random variableX we have

Nlim!1

1 N

XN

n=1

xn = E(X)

with probability 1. Let’s verify this theorem empirically.

(a) Generate samples from a normal distribution with mean 0 and variance 1.

(b) PlotN vs. the empirical mean N1 PN

n=1xn in logarithmic scale.

(c) How fast does the empirical mean approach the expectation?

Numpy: random, arange, sum, log;

matplotlib.pyplot: plot;

1

(2)

Exercise 4. The expectation of a random variable is a linear operator:

E(↵X) = ↵E(X) E(X+Y) = E(X) +E(Y)

Let Fn be a random variable describing the number of fixed points (elements that don’t change place) in a random permutation ofnelements.

(a) Write a function that takesnas an argument and returns a sample of lenght k from the distribution of Fn.

(b) Generate samples fromFn with a few di↵erent values ofn.

(c) Draw histograms of the di↵erent samples.

(d) Can you guess what the expected valueE(Fn) of the distribution might be?

(e) Use the linearity of the expectation operator to calculateE(Fn). (Hint: Take another random variableFin , such thatFin= 1 when thei:th element stays fixed, otherwiseFin = 0.Now we can writeFn=Pn

i=1Fin.) Numpy: permutation;

matplotlib.pyplot: hist;

Exercise 5.

(a) Write a function that

• takes 6 arguments: a sample sizen, a probability⇡(0⇡1), and the expectatations and variances of two univariate normal distributions.

• returns twon-element vectorsxandy, such that for eachi2{1, . . . , n}holds:

With probability⇡,y[i] = 0 andx[i] is a point from the first normal distribution otherwisey[i] = 1, andx[i] is a point from the second normal distribution.

(The distribution ofxis called a “Gaussian mixture”.)

(b) Visualize the data generated by the function with di↵erent values of the arguments.

(c) Can you come up with any example that follows such a distribution?

Numpy: random;

matplotlib.pyplot: scatter/hist;

2

Viittaukset

LIITTYVÄT TIEDOSTOT

machine = computer, computer program (in this course) learning = improving performance on a given task, based.. on experience

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

• Return a brief written report (as PDF, included in the same file as your pen-and-paper solutions) and one directory (as a zip or tar.gz file) including all your code.. • Do

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

In contrast, the amount of time taken by decision tree construction has a well-defined upper bound that depends only on the size of input (number of data points and variables), not

(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 expected error of the optimal classifier, by computer simulation, as follows: Generate 10 000 samples from the above model (for each sample, first randomly select y = 0 or y =