[SOLVED] Machine-Learning Homework 4

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon HW4-zlvdrq.zip (589.5 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

1. Logistic regression

Input:

1. (number of data points)

2. Function:

1. Generate data point: independently sampled from

2. Generate data point: independently sampled from

(

: mean, : variance)
, where and are

and

and

respectively.

, where and are respectively.

3. Use Logistic regression to separate and
and steepest gradient descent method during optimization.

In other words, when the Hessian is singular, use steepest descent for instead. You should come up with a reasonable rule to determine convergence.(a simple run out of the loop should be used as the ultimatum)

Output:

1. The confusion matrix and the sensitivity and specificity of the logistic regression applied to the training data .

2. Visualization
Plot the ground truth

Plot the predict result

Gradient descent Newton’s method

Use the Gaussian random number generator in homework 3.

Sample input & output (for reference only) Case 1:

. You should implement both Newton’s

1 Gradient descent: 2
3 w:

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
 -78.1766393662
   6.7233419236
  11.2430677919

Confusion Matrix:
Predict cluster 1 Predict cluster 2

Is cluster 1 50 0 Is cluster 2 0 50

Sensitivity (Successfully predict cluster 1): 1.00000 Specificity (Successfully predict cluster 2): 1.00000

Newton’s method:

w:
-118.3601516394
   8.7747332848
  10.1954120077

Confusion Matrix:
Predict cluster 1 Predict cluster 2

Is cluster 1 50 0 Is cluster 2 0 50

Sensitivity (Successfully predict cluster 1): 1.00000 Specificity (Successfully predict cluster 2): 1.00000

Case 2:

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

Gradient descent:

w:
 -71.1902536008
  46.0123814025
  54.6803199701

Confusion Matrix:
Predict cluster 1 Predict cluster 2

Is cluster 1 Iscluster2

16 34 3 47

Sensitivity (Successfully predict cluster 1): 0.32000 Specificity (Successfully predict cluster 2): 0.94000

Newton’smethod: w:

  -1.9045831451
   0.3940876974
   0.5695243849

Confusion Matrix:
Predict cluster 1 Predict cluster 2

Is cluster 1 Is cluster 2

40 10 10 40

Sensitivity (Successfully predict cluster 1): 0.80000 Specificity (Successfully predict cluster 2): 0.80000

2. EM algorithm

Input: MNIST training data and label sets. (Same as HW02) Function:

  1. Binningthegraylevelvalueintotwobins.Treatingallpixelsasrandomvariables following Bernoulli distributions. Note that each pixel follows a different Binomial distribution independent to others.
  2. Use EM algorithm to cluster each image into ten groups. You should come up with a reasonable rule to determine convergence. (a simple run out of the loop should be used as the ultimatum)

Output:

  1. For each digit, output a confusion matrix and the sensitivity and specificity of the clustering applied to the training data.
  2. Print out the imagination of numbers in your classifier

    Just like before, about the details please refer to HW02

Hint: The algorithm is a kind of unsupervised learning, so the labels are not used during training. But you can use these labels to help you to figure out which class belongs to which number.

In other words, you should find a way to assign label to each class which you classified before you compute the confusion matrix

Sample input & output (for reference only)

1 class0:
2 0000000000000000000000000000 3 0000000000000000000000000000

4 5 6 7 8 9

10
11
12
13
14
15

000 000 000 000 000 000 000 000 000 000 000 000

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

000 000 000 000 000 000 000 000 000 000 000 000 000 000

class

32
33
34
35
36
37
38
39
40
41
42

000 000 000 000 000 000 000 000 000 000 000

43
44
45
46
47
48

000 000 000 000 000 000

49 50 51 52

000 000 000 000

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0

000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000010000000000 000000000000111000000000 000000000001111000000000 000000000001110000000000 000000000001100000000000 000000000000100000000000 000000000000000000000000 000000000001000000000000 000000000011000000000000 000000000011000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000

1: 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000000000000000000 000000000110000000000000 000000000000011100000000 000000000000011100000000 000000000000011100000000 000000000000001100000000 000000000000001100000000 000000000000011100000000 000000000000011100000000 000000000000111000000000 000000000011111100000000 000000000111111100000000 000000000111111100000000 000000001110001100000000 000000000000000000000000

 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

0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000

… all other unlabeled imagination of numbers goes here …

class 9: 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000011110000000000 0000000000001111111000000000 0000000000011111111100000000 0000000000000000011100000000 0000000000000000001000000000 0000000000000000001000000000 0000000000000011111000000000 0000000000000111111100000000 0000000000011111111100000000 0000000000000000001100000000 0000000000000000001100000000 0000000001000000000100000000 0000000010000000000100000000 0000000010000000001100000000 0000000110000000011100000000 0000000110000000111000000000 0000000111000100110000000000 0000000011111011000000000000 0000000001111110000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000

No. of Iteration: 1, Difference: 3176.579389514846

class 0: 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000

102
103
104
105
106
107
108
109
110
111
112
113

00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000011000 00000000000000111000 00000000000000111000 00000000000001110000 00000000000001110000

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

00000000000001110000 00000000000001110000 00000000000000100000 00000000000000100000 00000000000001100000 00000000000000100000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000

… all other iterations goes here … class 9:

130
131
132
133
134
135
136
137
138
139
140

00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000011100 00000000000000111100 00000000000000111100 00000000000001110000 00000000000001100000 00000000000011000000 00000000000011000000

141
142
143
144
145
146

00000000000111000000 00000000000111000000 00000000000110001000 00000000001110011110 00000000001100001110 00000000001100000110

147
148
149
150

00000000001100000110 00000000001100001110 00000000001100011110 00000000001111111100

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0

0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000

0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000 0000000

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

0000000000111111100000000000 0000000000011110000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000

No. of Iteration: 10, Difference: 19.89546432548733

labeled class 0: 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000111110000000000 0000000000011111111000000000 0000000000111111111110000000 0000000001111111111110000000 0000000011111000000111000000 0000000011110000000011100000 0000000111100000000011100000 0000000111000000000001100000 0000001111000000000001110000 0000001110000000000001110000 0000001110000000000001110000 0000001110000000000011100000 0000001110000000000011100000 0000001110000000000111000000 0000001111000000001111000000 0000000111100000111110000000 0000000011111111111100000000 0000000001111111110000000000 0000000000011111000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000

labeled class 1: 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000

200 0000000000000000000000000000 201 0000000000000000000000000000 202 0000000000000001100000000000 203 0000000000000011100000000000 204 0000000000000011100000000000 205 0000000000000011100000000000 206 0000000000000011100000000000 207 0000000000000011000000000000 208 0000000000000111000000000000 209 0000000000000111000000000000 210 0000000000000111000000000000 211 0000000000000111000000000000

  1. 212  0000000000001110000000000000
  2. 213  0000000000001110000000000000
  3. 214  0000000000001110000000000000
  4. 215  0000000000001110000000000000
  5. 216  0000000000001100000000000000
  6. 217  0000000000000000000000000000
  7. 218  0000000000000000000000000000
  8. 219  0000000000000000000000000000
  9. 220  0000000000000000000000000000
  10. 221  0000000000000000000000000000
  11. 222  0000000000000000000000000000

223

224 … all other labeled imagination of numbers goes here … 225

  1. 226  labeledclass9:
  2. 227  0000000000000000000000000000

228 0000000000000000000000000000 229 0000000000000000000000000000 230 0000000000000000000000000000 231 0000000000000000000000000000 232 0000000000000000000000000000 233 0000000000000000000000000000 234 0000000000000000000000000000 235 0000000000111000000000000000 236 0000000001110000011000000000 237 0000000011100000011000000000 238 0000000011000000011000000000

239 0000000011000000011000000000 240 0000000011000000111000000000 241 0000000011000001111000000000 242 0000000011111111111000000000 243 0000000001111111111000000000 244 0000000000000000111000000000

245 0000000000000000110000000000 246 0000000000000000110000000000 247 0000000000000000110000000000 248 0000000000000000110000000000

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

0000000000000000100000000000 0000000000000000100000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000

Confusion Matrix 0:
Predict number 0 Predict not number 0

Is number 0 3023 2900 Isn’t number 0 113 53964

Sensitivity (Successfully Specificity (Successfully

predict number 0) : 0.51038 predict not number 0): 0.99791

Confusion Matrix 1:
Predict number 1 Predict not number 1

Is number 1 5986 756 Isn’t number 1 800 52458

Sensitivity (Successfully Specificity (Successfully

predict number 1) : 0.88787 predict not number 1): 0.98498

… all other confusion matrix goes here …

Confusion Matrix 9:
Predict number 9 Predict not number 9

Is number 9 2718 3231 Isn’t number 9 5147 48904

Sensitivity (Successfully Specificity (Successfully

predict number 9) : 0.45688 predict not number 9): 0.90478

Total iteration to converge: 10 Total error rate: 0.5081666666666667

  • HW4-zlvdrq.zip