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.
- The price of a flat.
- Whether an email is spam.
- Which of 200 species a photograph shows.
- The number of visitors to a museum on a given day.
- A probability that must lie between 0 and 1, given as a fraction.
- 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\).
- 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.
- How many hours would the above student need to study to have a 50% chance of getting a 6 in the machine learning class?
- Write \(\hat\beta_1\) as an odds ratio and say in one sentence what it means.
- 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.
- Write down the negative log-likelihood and drop the terms that do not depend on the parameters.
- 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.
- Why does a Poisson model have no separate noise parameter.
- 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.
- Of 100000 people, how many test positive.
- Of those, how many actually have the disease.
- 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.
- Load the MNIST data set.
- 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.
- Scale the input values to the interval \([0, 1)\) by dividing all pixel values by 255.
- Fit a linear classifier to the data. Be patient! This can take a few minutes. Hint: use
LogisticRegression(penalty=None). - Compute the misclassification rate and the confusion matrix on the training set.
- Use as test data rows 60001 to 70000 and compute the misclassification rate and the confusion matrix on this test set.
- Plot some of the correctly classified test images.
- Plot some of the wrongly classified training and test images. Are they also difficult for you to classify?
- Fit a network with one hidden layer of 128 relu neurons on the same 5000 rows, and report the same numbers.
- Plot some test images that the network gets right and the linear model gets wrong. What do they have in common.