# 2nd Terascale School for Machine Learning: Team 8
**Important:** You can use this hackmd pad to take notes together, identify key questions, and document progress. Please be constructive, inclusive and positive in your communication with your peers.
### Important links
* very illustrative [animations](https://github.com/dariyasydykova/open_projects/tree/master/ROC_animation) for the ROC curve
* Stanford [course](https://cs231n.github.io/) on CNNs
### Documentation
* School Indico webpage: https://indico.desy.de/event/28296/
* Main HackMD page: https://hackmd.io/@Z3k-IRVbRJuDU-0M-Yfqzw/SkEaiIIG_/edit
* Main website: https://deeplearning540.github.io/
### Video Conferencing
- the main zoom room is [here](https://cern.zoom.us/j/66120916180?pwd=aWtSVWdUNFFXV1FFSFQ4MEFsK1RlQT09):
- our team's zoom room is [here](https://cern.zoom.us/j/6451659169?pwd=QU4wNHVmV1FQcmxZN2hwYmlwSFJQdz09):
### Staying in Touch
- the main mattermost channel: [here](https://mattermost.web.cern.ch/signup_user_complete/?id=j93uppzm6ff9zg5brdeuqobfgw)
- our team's mattermost channel: [here](https://mattermost.web.cern.ch/terascale-ml/channels/group-8)
# Learning
Each lesson always follows the same structure and is expected to last about 1h.
1. learners watch the video :cinema:
2. learners answer at least one check-your-learning questions as a team (at best in a hackmd document) :heavy_check_mark:
3. learners dive into the exercise on their own if time permits :clock1:
:question: Instructors help with show stoppers like syntax errors where they can.
:computer: if you like to conduct the exercises, or code along during the videos, we suggest to use [google colab](colab.research.google.com/). Note, you may need a google account for this.
Each lesson has a jupyter notebook, that is half filled. The video lectures start from this notebook and provide content to fill in.
## Lessons
- Lesson 00: Preface
- Lesson 01: Diving into Regression [[video]](https://indico.desy.de/event/28296/contributions/99576/attachments/64395/79079/deeplearning540-lesson01-2021-02-19_17.59.48.mkv), [[learner notebook]](https://github.com/deeplearning540/lesson01/blob/main/lesson.ipynb)
- Lesson 02: Enter Clustering [[video]](https://indico.desy.de/event/28296/contributions/97975/attachments/64396/79084/deeplearning540_lesson02-2021-02-22_23.30.44.mkv), [[learner notebook]](https://github.com/deeplearning540/lesson02/blob/main/lesson.ipynb)
- Lesson 03: From Clustering To Classification [[video/part 1]](https://indico.desy.de/event/28296/contributions/97976/attachments/64398/79089/deeplearning540_lesson03-2021-02-23_23.14.33_part1.mkv), [[video/part 2]](https://indico.desy.de/event/28296/contributions/97976/attachments/64398/79097/deeplearning540_lesson03_part2-2021-02-26_22.37.04.mkv), [[learner notebook]](https://github.com/deeplearning540/lesson03/blob/main/lesson.ipynb)
- Lesson 04: Classification Performance ROCs [[video]](https://indico.desy.de/event/28296/contributions/97977/attachments/64400/79098/deeplearning540_lesson04-2021-02-24_18.09.02.mkv), [[learner notebook]](https://github.com/deeplearning540/lesson04/blob/main/lesson.ipynb)
- Lesson 05: Neural Networks as Code [[video]](https://indico.desy.de/event/28296/contributions/97977/attachments/64400/79101/deeplearning540_lesson05-2021-02-25_17.48.08.mkv), [[learner notebook]](https://github.com/deeplearning540/lesson05/blob/main/lesson.ipynb)
- Lesson 06: How did we train [[video]](https://indico.desy.de/event/28296/contributions/98225/attachments/64451/79196/deeplearning540_lesson06-2021-01-03_233847.mkv), [[slides]](https://indico.desy.de/event/28296/contributions/98225/attachments/64451/79197/deeplearning540-lesson06-slides.pdf), no jupyter notebook for this lesson
- Lesson 07: CNNs [[video/part 1]](https://indico.desy.de/event/28296/contributions/98226/attachments/64470/79239/deeplearning540_lesson07_part1-2021-03-02_17.11.15.mkv), [[video/part 2]](https://indico.desy.de/event/28296/contributions/98226/attachments/64470/79240/deeplearning540_lesson07_part2-2021-03-02_17.39.37.mkv) [[learner notebook]](https://github.com/deeplearning540/lesson07/blob/main/lesson07.ipynb)
- Lesson 08: Capstone project! [[link]](https://deeplearning540.github.io/lesson08/content.html#)
## Exercises
* [Lesson 01](https://deeplearning540.github.io/lesson01/content.html#exercises)
* [Lesson 02](https://deeplearning540.github.io/lesson02/content.html#exercises)
* [Lesson 03](https://deeplearning540.github.io/lesson03/content.html#exercises)
* [Lesson 04](https://deeplearning540.github.io/lesson04/content.html#exercises)
* [Lesson 05](https://deeplearning540.github.io/lesson05/content.html#exercises)
* [Lesson 06](https://deeplearning540.github.io/lesson06/content.html#exercises)
* [Lesson 07](https://deeplearning540.github.io/lesson07/content.html#exercises)
# Notes
## Lesson 01
<details>
<summary>
click!
</summary>
### Video:
\<notes here\>
### Check your Learning:
> **Question 1**
> In the following, the order of steps was confused, please rearrange:
1) collect training data, compute accuracy, predict new data, fit training data
2) compute accuracy, collect training data, predict new data, fit training data
3) collect training data, fit training data, compute accuracy, predict new data
++++++++
4) collect training data, predict new data, fit training data, compute accuracy
y = 0, 0, 1
y_pred = 0, 1, 1
acc = 2/3
Accuracy: TP + TN / (TP + TN + FP + FN) (for binary classification)
> **Question 2**
> The least squares method for an input data pair `x` and `y` derives it’s name as it …
1) Minimizes the sum of the product of x*y
2) Minimizes the sum of the absolute difference between y and the predicted y_hat
3) Minimizes the sum of the squared difference between y and the predicted y_hat
++++++
4) Minimizes the sum of y**2 and x**2
> **Question 3**
> NaN stands for not-a-number. When loading a dataset with `pandas`, NaN values occur in the loaded data because …
1) Input files contain string values in a column
++
2) Computational Problems occurred, like computing the square root of a negative number
+
3) Data could not be parsed correctly when reading input files into memory
+++++
4) There was no internet connection
5) I think all first three answers are kind of correct?
+
### Exercises:
\<notes here\>
</details>
## Lesson 02
<details>
<summary>
click!
</summary>
### Video:
\<notes here\>
### Check your Learning:
> **Question 1**
> You are provided a table of measurements from a weather station. Each measurements comes with values for temperature, precipation, cloud structure, date, humidity, and a quality ID. The latter tells you if the instrument was performing OK. You’d like to learn an algorithm that is able to predict the quality ID (5 possible integer values from 0 to 4) for any new data coming in. This falls into …
1) Supervised Learning
2) Unsupervised Learning
3) Reinforcement Learning
> **Question 02**
> You are given a dataset of iris flowers. The data set consists of 50 samples from each of three species of Iris (Iris setosa, Iris virginica and Iris versicolor). Four features were measured from each sample: the length and the width of the sepals and petals, in centimeters. Which of the following feature combinations lend themselves for clustering? See [this overview plot](https://en.wikipedia.org/wiki/File:Iris_dataset_scatterplot.svg) for help.
1) Sepal.Length versus Sepal.Width
2) Sepal.Length versus Petal.Width
3) Petal.Length versus Petal.Width
4) Sepal.Width versus Petal.Width
> **Question 03**
> You are helping to organize a conference of more than 1000 attendants. All participants have already paid and are expecting to pick up their conference t-shirt on the first day. Your team is in shock as it discovers that t-shirt sizes have not been recorded during online registration. However, all participants were asked to provide their age, gender, body height and weight. To help out, you sit down to write a python script that predicts the t-shirt size for each participant using a clustering algorithm. You know that you can only get 7 t-shirt sizes (XS, S, M, L, XL, XXL). This falls into:
1) Supervised Learning
2) Unsupervised Learning
3) Reinforcement Learning
### Exercises:
\<notes here\>
</details>
## Lesson 03
<details>
<summary>
click!
</summary>
### Video:
\<notes here\>
### Check your Learning:
> **Question 1**
> When using the k-Nearest-Neighbor (kNN) algorithm for classifying a query point x_q, the k stands for:
1) the number of neighbors that must have a given label for the query point to get this label assigned
2) the number of classes occurring in the data set
3) the number of observations that define a neighborhood
++++
4) the number of clusters in the dataset+
> **Question 02**
> When going through tutorials and exercises that discuss the k-Nearest-Neighbor (kNN) method, you observe that k is typically chosen to be an odd number. Checking the code, sklearn also access even numbers for k. Why do people tend to choose odd numbers?
1) tradition that often works best in practice
2) odd numbers prevent ties from happening with the majaority vote
+++++
3) this way, the total number of samples in the neighborhood is always even as one has to add the query sample
4) odd numbers prevent ties from happening with the plurarity vote
> **Question 03**
> What is the majority vote and the plurality vote if the 8 nearest neighbors to your unknown data point are of the following classes:
a)
* class 1: 3
* class 2: 2
* class 3: 2
* class 4: 1
majority vote: _-___- plurality vote: _1___1
b)
* class 1: 5
* class 2: 2
* class 3: 1
majority vote: _1___1 plurality vote: _1___1
> **Question 04**
> Find the four hidden bug(s)!
```python
from sklearn.neighbors import KNeighborsClassifier as knn
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
# ... load dataset ...
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size = 1.5, #<--
random_state = 42)
kmeans = knn(n_neighbors=5)
kmeans = kmeans.fit(X_train, y_train)
y_test_hat = kmeans.predict(X_train)
cm = confusion_matrix(y_train, y_test_hat)
accuracy = (cm[0,0]+cm[0,1]) / cm.sum()
```
### Exercises:
\<notes here\>
</details>
## Lesson 04
<details>
<summary>
click!
</summary>
### Video:
\<notes here\>
### Check your Learning:
> **Question 1**
> The ROC acronym stands for
1) Receiver Operator Curve
2) Receiving Operates Curves
3) Receiver Operating Characteristic +++
4) Reception Occlusion Characteristic
> **Question 02**
> Fill in the blanks!
A k-Nearest-Neighbor (kNN) classifier can produce a probability when predicting the class label of an unseen sample x_q.
This can be achieved by counting class (labels)_______ in the training set neighborhood of this query point.
1 0 0 x 0 0 1 1
0: 4/7
1: 3/7
For a k=7 neighborhood, the threshold to decide for any given class in this neighborhood is calculated as 4/__(7).
In the same setting (k=7), let’s assume we find 5 labels for class 1 and 2 labels for class 0.
This means, that we get two probabilities, which are ___5/7__ for class 1 and _2/7___ for class 0.
### Exercises:
\<notes here\>
</details>
## Lesson 05
<details>
<summary>
click!
</summary>
### Video:
\<notes here\>
### Check your Learning:
> **Question 1**
> A hidden layer of an artificial neural network consists a fixed set of parts. These are …
1) weights (W) and a bias term (b)
2) weights (W) and a non-linear activation function (F)
3) a bias term (b) and a non-linear activation function (F)
4) weights (W), a bias term (b) and a non-linear activation function (F)
> **Question 02**
> Unlike `scikit-learn`, keras is a machine learning framework that …
1) offers one-stop-shop prepared networks that are already published
2) offers building blocks to construct neural networks on CPU or GPU architectures
3) offers an API to either wrap around backends (keras library) or represents the high-level API for tensorflow
4) all of the above
### Exercises:
\<notes here\>
</details>
## Lesson 06
<details>
<summary>
click!
</summary>
### Video:
\<notes here\>
### Check your Learning:
> **Question 1**
> The advantage of mini-batched based optimisation compared to online gradient descent or full data set gradient descent is …
1) a mini-batch represents the entire data set and hence is enough to optimize on
2) the optimisation converges faster ++++
3) the optimisation can be performed in memory independent of the data set size
4) the optimisation will converge always into a global optimum
> **Question 02**
> Categorical Cross-Entropy is part of a well-known divergence in statistics. A divergence is a method to compare two probability density functions. It provides a large value if two distributions are different and a small value if they are similar. This well-known divergance that spurrs the Categorical Cross-Entropy is …
1) Mean-Squared-Error divergence
2) Negative-Log-Likelihood divergence
3) Kullback-Leibler divergence +++
4) Maximum-Mean-Discreptancy divergence
> **Question 03**
> The gradient that is required for gradient descent is the gradient …
1) of the loss function L with respect to the testset input data, df/dx, given the network parameters theta
2) of the network f with respect to the input data, df/dx, given the network parameters theta
3) of the network f with respect to the network parameters, df/dtheta, given the training data x
4) of the loss function L with respect to the network parameters, df/dtheta, given the training data x++++
### Exercises:
\<notes here\>
</details>
## Lesson 07
<details>
<summary>
click!
</summary>
### Video:
\<notes here\>
### Check your Learning:
> **Question 1**
> Fill in the blanks to produce a CNN for classification!
```python
from tensorflow import keras
from keras.layers import Input, Dense, Dropout, Flatten, ____2D, _________2D
#load the data
#define the network
conv1 = Conv2D(16, kernel_size=(3,3), activation=’______’, input_shape=X_train.shape[1:])
conv2 = ______(32, kernel_size=(3,3), activation=’relu’)
mpool = _________(pool_size=(2,2))
## MLP layers
flat = Flatten()
dense1 = Dense(128, _____________)
dense2 = Dense(num_classes, __________)
#compile and train
x_inputs = Input(shape=X_train.shape[1:])
x = conv1(_______)
x = ______(x)
x = ______(x)
x = flat(x)
x = dense1(x)
output_yhat = dense2(x)
model = keras.Model(inputs = _______, outputs = _______, name=”hello-world-cnn”)
```
> **Question 02**
> The Flatten operation rearranges an input image (or feature map) into a sequence of numbers. How does it perform this?
1) the pixel intensities are averaged per row and concatenated
2) all rows of the input are added and provided as a result
3) all columns of the input are concatenated (from top to bottom)
4) all rows of the input are concatenated (from top to bottom)+
> **Question 03**
> For an input image shape of 28x28 what is the shape of the feature map after running the image through a single 5x5 convolutional filter?
1) 24x28
2) 20x28
3) 26x26 +
4) 24x24 +++
> **Question 04**
> For an MNIST input image, how many parameters does a Conv2D layer require when being defined to produce 16 feature maps as output and a 3x3 neighborhood. How many parameters does a Dense layer with 16 outputs have? Compute the two parameter counts!
9232
### Exercises:
\<notes here\>
</details>