[SOLVED] NYCU 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 ML_HW04-qpno8b.zip (561.5 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

 

Description :
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

  1. 4  0000000000000000000000000000
  2. 5  0000000000000000000000000000
  3. 6  0000000000000000000000000000
  4. 7  0000000000000000000000000000
  5. 8  0000000000000000000000000000
  6. 9  0000000000000000000000000000
  7. 10  0000000000000000000000000000
  8. 11  0000000000000000000000000000
  9. 12  0000000000000000000000000000
  10. 13  0000000000000000000000000000
  11. 14  0000000000000000100000000000
  12. 15  0000000000000001110000000000
  13. 16  0000000000000011110000000000
  14. 17  0000000000000011100000000000
  15. 18  0000000000000011000000000000
  16. 19  0000000000000001000000000000
  17. 20  0000000000000000000000000000
  18. 21  0000000000000010000000000000
  19. 22  0000000000000110000000000000
  20. 23  0000000000000110000000000000
  21. 24  0000000000000000000000000000
  22. 25  0000000000000000000000000000
  23. 26  0000000000000000000000000000
  24. 27  0000000000000000000000000000
  25. 28  0000000000000000000000000000
  26. 29  0000000000000000000000000000

30

  1. 31  class1:
  2. 32  0000000000000000000000000000
  3. 33  0000000000000000000000000000
  4. 34  0000000000000000000000000000
  5. 35  0000000000000000000000000000
  6. 36  0000000000000000000000000000
  7. 37  0000000000000000000000000000
  8. 38  0000000000000000000000000000
  9. 39  0000000000001100000000000000
  10. 40  0000000000000000111000000000
  11. 41  0000000000000000111000000000
  12. 42  0000000000000000111000000000
  13. 43  0000000000000000011000000000
  14. 44  0000000000000000011000000000
  15. 45  0000000000000000111000000000
  16. 46  0000000000000000111000000000
  17. 47  0000000000000001110000000000
  18. 48  0000000000000111111000000000
  19. 49  0000000000001111111000000000
  20. 50  0000000000001111111000000000
  21. 51  0000000000011100011000000000
  22. 52  0000000000000000000000000000
  1. 53  0000000000000000000000000000
  2. 54  0000000000000000000000000000
  3. 55  0000000000000000000000000000
  4. 56  0000000000000000000000000000
  5. 57  0000000000000000000000000000
  6. 58  0000000000000000000000000000
  7. 59  0000000000000000000000000000

60

61 … all other unlabeled imagination of numbers goes here … 62

  1. 63  class9:
  2. 64  0000000000000000000000000000
  3. 65  0000000000000000000000000000
  4. 66  0000000000000000000000000000
  5. 67  0000000000000000000000000000
  6. 68  0000000000000011110000000000
  7. 69  0000000000001111111000000000
  8. 70  0000000000011111111100000000
  9. 71  0000000000000000011100000000
  10. 72  0000000000000000001000000000
  11. 73  0000000000000000001000000000
  12. 74  0000000000000011111000000000
  13. 75  0000000000000111111100000000
  14. 76  0000000000011111111100000000
  15. 77  0000000000000000001100000000
  16. 78  0000000000000000001100000000
  17. 79  0000000001000000000100000000
  18. 80  0000000010000000000100000000
  19. 81  0000000010000000001100000000
  20. 82  0000000110000000011100000000
  21. 83  0000000110000000111000000000
  22. 84  0000000111000100110000000000
  23. 85  0000000011111011000000000000
  24. 86  0000000001111110000000000000
  25. 87  0000000000000000000000000000
  26. 88  0000000000000000000000000000
  27. 89  0000000000000000000000000000
  28. 90  0000000000000000000000000000
  29. 91  0000000000000000000000000000

92

93 No. of Iteration: 1, Difference: 3176.579389514846 94
95
96

  1. 97  class 0:
  2. 98  0000000000000000000000000000
  3. 99  0000000000000000000000000000
  4. 100  0000000000000000000000000000
  5. 101  0000000000000000000000000000
  1. 102  0000000000000000000000000000
  2. 103  0000000000000000000000000000
  3. 104  0000000000000000000000000000
  4. 105  0000000000000000000000000000
  5. 106  0000000000000000000000000000
  6. 107  0000000000000000000000000000
  7. 108  0000000000000000000000000000
  8. 109  0000000000000001100000000000
  9. 110  0000000000000011100000000000
  10. 111  0000000000000011100000000000
  11. 112  0000000000000111000000000000
  12. 113  0000000000000111000000000000
  13. 114  0000000000000111000000000000
  14. 115  0000000000000111000000000000
  15. 116  0000000000000010000000000000
  16. 117  0000000000000010000000000000
  17. 118  0000000000000110000000000000
  18. 119  0000000000000010000000000000
  19. 120  0000000000000000000000000000
  20. 121  0000000000000000000000000000
  21. 122  0000000000000000000000000000
  22. 123  0000000000000000000000000000
  23. 124  0000000000000000000000000000
  24. 125  0000000000000000000000000000

126

127 … all other iterations goes here … 128

  1. 129  class 9:
  2. 130  0000000000000000000000000000
  3. 131  0000000000000000000000000000
  4. 132  0000000000000000000000000000
  5. 133  0000000000000000000000000000
  6. 134  0000000000000001110000000000
  7. 135  0000000000000011110000000000
  8. 136  0000000000000011110000000000
  9. 137  0000000000000111000000000000
  10. 138  0000000000000110000000000000
  11. 139  0000000000001100000000000000
  12. 140  0000000000001100000000000000
  13. 141  0000000000011100000000000000
  14. 142  0000000000011100000000000000
  15. 143  0000000000011000100000000000
  16. 144  0000000000111001111000000000
  17. 145  0000000000110000111000000000
  18. 146  0000000000110000011000000000
  19. 147  0000000000110000011000000000
  20. 148  0000000000110000111000000000
  21. 149  0000000000110001111000000000
  22. 150  0000000000111111110000000000
  1. 151  0000000000111111100000000000
  2. 152  0000000000011110000000000000
  3. 153  0000000000000000000000000000
  4. 154  0000000000000000000000000000
  5. 155  0000000000000000000000000000
  6. 156  0000000000000000000000000000
  7. 157  0000000000000000000000000000

158

159 No.ofIteration:10,Difference:19.89546432548733 160
161
162

163

  1. 164  labeled class 0:
  2. 165  0000000000000000000000000000
  3. 166  0000000000000000000000000000
  4. 167  0000000000000000000000000000
  5. 168  0000000000000000000000000000
  6. 169  0000000000000000000000000000
  7. 170  0000000000000111110000000000
  8. 171  0000000000011111111000000000
  9. 172  0000000000111111111110000000
  10. 173  0000000001111111111110000000
  11. 174  0000000011111000000111000000
  12. 175  0000000011110000000011100000
  13. 176  0000000111100000000011100000
  14. 177  0000000111000000000001100000
  15. 178  0000001111000000000001110000
  16. 179  0000001110000000000001110000
  17. 180  0000001110000000000001110000
  18. 181  0000001110000000000011100000
  19. 182  0000001110000000000011100000
  20. 183  0000001110000000000111000000
  21. 184  0000001111000000001111000000
  22. 185  0000000111100000111110000000
  23. 186  0000000011111111111100000000
  24. 187  0000000001111111110000000000
  25. 188  0000000000011111000000000000
  26. 189  0000000000000000000000000000
  27. 190  0000000000000000000000000000
  28. 191  0000000000000000000000000000
  29. 192  0000000000000000000000000000

193

  1. 194  labeled class 1:
  2. 195  0000000000000000000000000000
  3. 196  0000000000000000000000000000
  4. 197  0000000000000000000000000000
  5. 198  0000000000000000000000000000
  6. 199  0000000000000000000000000000
  1. 200  0000000000000000000000000000
  2. 201  0000000000000000000000000000
  3. 202  0000000000000001100000000000
  4. 203  0000000000000011100000000000
  5. 204  0000000000000011100000000000
  6. 205  0000000000000011100000000000
  7. 206  0000000000000011100000000000
  8. 207  0000000000000011000000000000
  9. 208  0000000000000111000000000000
  10. 209  0000000000000111000000000000
  11. 210  0000000000000111000000000000
  12. 211  0000000000000111000000000000
  13. 212  0000000000001110000000000000
  14. 213  0000000000001110000000000000
  15. 214  0000000000001110000000000000
  16. 215  0000000000001110000000000000
  17. 216  0000000000001100000000000000
  18. 217  0000000000000000000000000000
  19. 218  0000000000000000000000000000
  20. 219  0000000000000000000000000000
  21. 220  0000000000000000000000000000
  22. 221  0000000000000000000000000000
  23. 222  0000000000000000000000000000

223

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

  1. 226  labeledclass9:
  2. 227  0000000000000000000000000000
  3. 228  0000000000000000000000000000
  4. 229  0000000000000000000000000000
  5. 230  0000000000000000000000000000
  6. 231  0000000000000000000000000000
  7. 232  0000000000000000000000000000
  8. 233  0000000000000000000000000000
  9. 234  0000000000000000000000000000
  10. 235  0000000000111000000000000000
  11. 236  0000000001110000011000000000
  12. 237  0000000011100000011000000000
  13. 238  0000000011000000011000000000
  14. 239  0000000011000000011000000000
  15. 240  0000000011000000111000000000
  16. 241  0000000011000001111000000000
  17. 242  0000000011111111111000000000
  18. 243  0000000001111111111000000000
  19. 244  0000000000000000111000000000
  20. 245  0000000000000000110000000000
  21. 246  0000000000000000110000000000
  22. 247  0000000000000000110000000000
  23. 248  0000000000000000110000000000

249 00000

0000000000

0100000000

000

250 00000

0000000000

0100000000

000

251 00000

0000000000

0000000000

000

252 00000

0000000000

0000000000

000

253 00000

0000000000

0000000000

000

254 00000

0000000000

0000000000

000

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

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

  • ML_HW04-qpno8b.zip