Skip to main content

Exercises

Exercises

Exercise 1

For each response below, say which distribution, which output layer and which loss you would use, and why. Then say whether a linear \(\eta\) is likely to be enough, and what would tell you that it is not.

  1. The price of a flat.
  2. Whether an email is spam.
  3. Which of 200 species a photograph shows.
  4. The number of visitors to a museum on a given day.
  5. A probability that must lie between 0 and 1, given as a fraction.
  6. The time until a component fails.

Exercise 2

Suppose we collect data for a group of students in a machine learning class with variables \(X_1 =\) hours studied, \(X_2 =\) grade in statistics class, and \(Y =\) receive a 6 in the machine learning class. We fit a logistic regression and produce estimated coefficients, \(\hat{\beta}_0 = -6\), \(\hat{\beta}_1 = 0.025\), \(\hat{\beta}_2 = 1\).

  1. Estimate the probability that a student who studies for 75 hours and had a 4 in the statistics class gets a 6 in the machine learning class.
  2. How many hours would the above student need to study to have a 50% chance of getting a 6 in the machine learning class?
  3. Write \(\hat\beta_1\) as an odds ratio and say in one sentence what it means.
  4. A network fitted to the same data reaches a higher test accuracy. Which of the three answers above can you still give, and which can you not.

Exercise 3

We model counts with a Poisson distribution and a log link.

  1. Write down the negative log-likelihood and drop the terms that do not depend on the parameters.
  2. A coefficient in the linear version is 0.2. By what factor does the expected count change for a one unit increase in that predictor.
  3. Why does a Poisson model have no separate noise parameter.
  4. A colleague fits a linear regression to the same counts and reports a smaller mean squared error than the Poisson model. Is that an argument for the linear model. Say what you would compute instead.

Exercise 4

A test has sensitivity 0.99 and specificity 0.95. The disease affects 1 person in 1000.

  1. Of 100000 people, how many test positive.
  2. Of those, how many actually have the disease.
  3. The AUC of this test is high. Explain why that is not enough to make it useful for screening, and what you would change.

Exercise 5

In this exercise we perform linear classification of the MNIST handwritten digits dataset.

  1. Load the MNIST data set.
  2. Usually the first 60’000 images are taken as training set, but for this exercise we recommend to use fewer rows, e.g. the first 5000.
  3. Scale the input values to the interval \([0, 1)\) by dividing all pixel values by 255.
  4. Fit a linear classifier to the data. Be patient! This can take a few minutes. Hint: use LogisticRegression(penalty=None).
  5. Compute the misclassification rate and the confusion matrix on the training set.
  6. Use as test data rows 60001 to 70000 and compute the misclassification rate and the confusion matrix on this test set.
  7. Plot some of the correctly classified test images.
  8. Plot some of the wrongly classified training and test images. Are they also difficult for you to classify?
  9. Fit a network with one hidden layer of 128 relu neurons on the same 5000 rows, and report the same numbers.
  10. Plot some test images that the network gets right and the linear model gets wrong. What do they have in common.