forked from georgeka98/INFR10069-2020-CW2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment_2.tex
521 lines (355 loc) · 13.1 KB
/
Assignment_2.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IAML 2020 Assignment 2 %
% %
% %
% Authors: Hiroshi Shimodaira and JinHong Lu %
% Based on: Assignment 1 by Oisin Mac Aodha, and %
% Octave Mariotti %
% Using template from: Michael P. J. Camilleri and %
% Traiko Dinev. %
% %
% Based on the Cleese Assignment Template for Students %
% from http://www.LaTeXTemplates.com. %
% %
% Original Author: Vel (vel@LaTeXTemplates.com) %
% %
% License: %
% CC BY-NC-SA 3.0 %
% (http://creativecommons.org/licenses/by-nc-sa/3.0/) %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%--------------------------------------------------------
% IMPORTANT: Do not touch anything in this part
\documentclass[12pt]{article}
\input{style.tex}
% Options for Formatting Output
\global\setbool{clearon}{true} %
\global\setbool{authoron}{true} %
\ifbool{authoron}{\rhead{\small{\assignmentAuthorName}}\cfoot{\small{\assignmentAuthorName}}}{\rhead{}}
\newcommand{\assignmentQuestionName}{Question}
\newcommand{\assignmentTitle}{Assignment\ \#2}
\newcommand{\assignmentClass}{IAML -- INFR10069 (LEVEL 10)}
\newcommand{\assignmentWarning}{NO LATE SUBMISSIONS} %
\newcommand{\assignmentDueDate}{Monday,\ November\ 23,\ 2020 @ 16:00}
%--------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% NOTE: YOU NEED TO ENTER YOUR STUDENT ID BELOW.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --------------------------------------------------------
% IMPORTANT: Specify your Student ID below. You will need to uncomment the line, else compilation will fail. Make sure to specify your student ID correctly, otherwise we may not be able to identify your work and you will be marked as missing.
%\newcommand{\assignmentAuthorName}{s1234567}
%--------------------------------------------------------
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%============================================================================%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
%
% Question 1
%
\begin{question}{(30 total points) Image data analysis with PCA}
\questiontext{In this question we employ PCA to analyse image data}
\medskip
%==============================
% Q1.1
\begin{subquestion}{(3 points)
Once you have applied the normalisation from Step 1 to Step 4 above,
report the values of the first 4 elements for the first training
sample in \texttt{Xtrn\_nm},
i.e. \texttt{Xtrn\_nm[0,:]} and the last training sample,
i.e. \texttt{Xtrn\_nm[-1,:]}.
} \label{Q1.1}
\begin{answerbox}{10em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
% Q1.2
\begin{subquestion}{(4 points)
Using {\tt Xtrn} and Euclidean distance
measure, for each class,
find the two closest samples and two furthest
samples of that class to the mean vector of the class.
} \label{Q1.2}
\begin{answerbox}{52em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% Q1.3
\begin{subquestion}{(3 points)
Apply Principal Component Analysis (PCA) to the data of {\tt
Xtrn\_nm} using
\href{https://scikit-learn.org/0.19/modules/generated/sklearn.decomposition.PCA.html}{sklearn.decomposition.PCA},
and report the variances of projected data for the first five principal
components in a table.
Note that you should use {\tt Xtrn\_nm} instead of {\tt Xtrn}.
} \label{Q1.pca.variance}
\begin{answerbox}{15em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%==============================
% Q1.4
\begin{subquestion}{(3 points)
Plot a graph of the cumulative explained variance ratio as a
function of the number of principal components, $K$, where $1
\le K \le 784$.
Discuss the result briefly.
} \label{Q1.plot.pca.variance}
\begin{answerbox}{30em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%==============================
% Q1.5
\begin{subquestion}{(4 points)
Display the images of the first 10 principal components in
a 2-by-5 grid, putting the image of 1st principal component on
the top left corner, followed by the one of 2nd component to the right.
Discuss your findings briefly.
} \label{Q1.disp.pca}
\begin{answerbox}{35em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%==============================
% Q1.6
\begin{subquestion}{(5 points)
Using \texttt{Xtrn\_nm},
for each class and for each number of principal components $K =
5, 20, 50, 200$, apply dimensionality reduction with PCA to the
first sample in the class, reconstruct the sample from the
dimensionality-reduced sample, and
report the Root Mean Square Error (RMSE) between the
original sample in {\tt Xtrn\_nm} and reconstructed one.
} \label{Q1.6}
\begin{answerbox}{25em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%==============================
% Q1.7
\begin{subquestion}{(4 points)
Display the image for each of the reconstructed samples in
a 10-by-4 grid, where each row corresponds to a class and
each row column corresponds to a value of $K=5, \; 20, \; 50, \; 200$.
} \label{Q1.7}
\begin{answerbox}{52em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%==============================
%
%==============================
% Q1.8
\begin{subquestion}{(4 points)
Plot all the training samples (\texttt{Xtrn\_nm}) on the
two-dimensional PCA plane you obtained in \refQ{Q1.pca.variance}, where each sample is
represented as a small point with a colour specific to the class of
the sample. Use the 'coolwarm' colormap for plotting.
} \label{Q1.8}
\begin{answerbox}{40em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
%==============================
\end{question}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%============================================================================%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
%
% Question 2
%
\begin{question}{(25 total points) Logistic regression and SVM}
\questiontext{In this question we will explore
classification of image data with logistic regression and support
vector machines (SVM) and visualisation
of decision regions.
}
\medskip
%==============================
% Q2.1
\begin{subquestion}{(3 points)
Carry out a classification experiment with
\href{https://scikit-learn.org/0.19/modules/generated/sklearn.linear\_model.LogisticRegression.html}{multinomial logistic regression},
and report the classification accuracy and confusion matrix (in
numbers rather than in graphical representation such as heatmap)
for the test set.
} \label{Q2.1}
\begin{answerbox}{30em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q2.2
\begin{subquestion}{(3 points)
Carry out a classification experiment with
\href{https://scikit-learn.org/0.19/modules/generated/sklearn.svm.SVC.html}{SVM classifiers}, and report the
mean accuracy and confusion matrix (in numbers) for the test
set.
} \label{Q2.2}
\begin{answerbox}{30em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q2.3
\begin{subquestion}{(6 points)
We now want to visualise the decision regions for the logistic
regression classifier we trained in \refQ{Q2.1}.
} \label{Q2.3}
\begin{answerbox}{35em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q2.4
\begin{subquestion}{(4 points)
Using the same method as the one above, plot the decision regions for
the SVM classifier you trained in \refQ{Q2.2}.
Comparing the result with that you obtained in \refQ{Q2.3}, discuss your
findings briefly.
} \label{Q2.4}
\begin{answerbox}{35em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q2.5
\begin{subquestion}{(6 points)
We used default parameters for the SVM in \refQ{Q2.2}.
We now want to tune the parameters by using cross-validation.
To reduce the time for experiments, you pick up the first 1000
training samples from each class to create \texttt{Xsmall}, so that \texttt{Xsmall}
contains 10,000 samples in total. Accordingly, you create
labels, \texttt{Ysmall}.
} \label{Q2.5}
\begin{answerbox}{30em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q2.6
\begin{subquestion}{(3 points)
Train the SVM classifier on the whole training set by using the
optimal value of $C$ you found in \refQ{Q2.5}.
} \label{Q2.6}
\begin{answerbox}{10em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%
%
\end{question}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%============================================================================%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
%
% Question 3
%
\begin{question}{(20 total points) Clustering and Gaussian Mixture Models}
\questiontext{In this question we will explore K-means clustering,
hierarchical clustering, and GMMs.
}
\medskip
%==============================
% Q3.1
\begin{subquestion}{(3 points)
Apply k-means clustering on {\tt Xtrn} for $k = 22$, where we use
\href{https://scikit-learn.org/0.19/modules/generated/sklearn.cluster.KMeans.html}{sklearn.cluster.KMeans}
with the parameters {\tt n\_clusters=22} and {\tt random\_state=1}.
Report the sum of squared distances of samples to their closest
cluster centre, and the number of samples for each cluster.
} \label{Q3.1}
\begin{answerbox}{35em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q3.2
\begin{subquestion}{(3 points)
Using the training set only,
calculate the mean vector for each language, and plot the mean
vectors of all the 22 languages on a 2D-PCA plane, where you
apply PCA on the set of 22 mean vectors without applying
standardisation.
On the same figure, plot the cluster centres obtained in \refQ{Q3.1}.
} \label{Q3.2}
\begin{answerbox}{35em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q3.3
\begin{subquestion}{(3 points)
We now apply hierarchical clustering on the training data set
to see if there are any structures in the spoken languages.
} \label{Q3.3}
\begin{answerbox}{35em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q3.4
\begin{subquestion}{(5 points)
We here extend the hierarchical clustering done in \refQ{Q3.3} by
using multiple samples from each language.
} \label{Q3.4}
\begin{answerbox}{50em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
% ==============================
%
%==============================
% Q3.5
\begin{subquestion}{(6 points)
We now consider Gaussian mixture model (GMM), whose
probability distribution function (pdf) is given as
a linear combination of Gaussian or normal distributions, i.e.,
} \label{Q3.5}
\begin{answerbox}{30em}
Your Answer Here
\end{answerbox}
\end{subquestion}
%
%==============================
% ==============================
\end{question}
\end{document}