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: 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: 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:
- Binningthegraylevelvalueintotwobins.Treatingallpixelsasrandomvariables following Bernoulli distributions. Note that each pixel follows a different Binomial distribution independent to others.
- 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:
- For each digit, output a confusion matrix and the sensitivity and specificity of the clustering applied to the training data.
- 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 0000000000000000000000000000
- 5 0000000000000000000000000000
- 6 0000000000000000000000000000
- 7 0000000000000000000000000000
- 8 0000000000000000000000000000
- 9 0000000000000000000000000000
- 10 0000000000000000000000000000
- 11 0000000000000000000000000000
- 12 0000000000000000000000000000
- 13 0000000000000000000000000000
- 14 0000000000000000100000000000
- 15 0000000000000001110000000000
- 16 0000000000000011110000000000
- 17 0000000000000011100000000000
- 18 0000000000000011000000000000
- 19 0000000000000001000000000000
- 20 0000000000000000000000000000
- 21 0000000000000010000000000000
- 22 0000000000000110000000000000
- 23 0000000000000110000000000000
- 24 0000000000000000000000000000
- 25 0000000000000000000000000000
- 26 0000000000000000000000000000
- 27 0000000000000000000000000000
- 28 0000000000000000000000000000
- 29 0000000000000000000000000000
30
- 31 class1:
- 32 0000000000000000000000000000
- 33 0000000000000000000000000000
- 34 0000000000000000000000000000
- 35 0000000000000000000000000000
- 36 0000000000000000000000000000
- 37 0000000000000000000000000000
- 38 0000000000000000000000000000
- 39 0000000000001100000000000000
- 40 0000000000000000111000000000
- 41 0000000000000000111000000000
- 42 0000000000000000111000000000
- 43 0000000000000000011000000000
- 44 0000000000000000011000000000
- 45 0000000000000000111000000000
- 46 0000000000000000111000000000
- 47 0000000000000001110000000000
- 48 0000000000000111111000000000
- 49 0000000000001111111000000000
- 50 0000000000001111111000000000
- 51 0000000000011100011000000000
- 52 0000000000000000000000000000
- 53 0000000000000000000000000000
- 54 0000000000000000000000000000
- 55 0000000000000000000000000000
- 56 0000000000000000000000000000
- 57 0000000000000000000000000000
- 58 0000000000000000000000000000
- 59 0000000000000000000000000000
60
61 … all other unlabeled imagination of numbers goes here … 62
- 63 class9:
- 64 0000000000000000000000000000
- 65 0000000000000000000000000000
- 66 0000000000000000000000000000
- 67 0000000000000000000000000000
- 68 0000000000000011110000000000
- 69 0000000000001111111000000000
- 70 0000000000011111111100000000
- 71 0000000000000000011100000000
- 72 0000000000000000001000000000
- 73 0000000000000000001000000000
- 74 0000000000000011111000000000
- 75 0000000000000111111100000000
- 76 0000000000011111111100000000
- 77 0000000000000000001100000000
- 78 0000000000000000001100000000
- 79 0000000001000000000100000000
- 80 0000000010000000000100000000
- 81 0000000010000000001100000000
- 82 0000000110000000011100000000
- 83 0000000110000000111000000000
- 84 0000000111000100110000000000
- 85 0000000011111011000000000000
- 86 0000000001111110000000000000
- 87 0000000000000000000000000000
- 88 0000000000000000000000000000
- 89 0000000000000000000000000000
- 90 0000000000000000000000000000
- 91 0000000000000000000000000000
92
93 No. of Iteration: 1, Difference: 3176.579389514846 94
95
96
- 97 class 0:
- 98 0000000000000000000000000000
- 99 0000000000000000000000000000
- 100 0000000000000000000000000000
- 101 0000000000000000000000000000
- 102 0000000000000000000000000000
- 103 0000000000000000000000000000
- 104 0000000000000000000000000000
- 105 0000000000000000000000000000
- 106 0000000000000000000000000000
- 107 0000000000000000000000000000
- 108 0000000000000000000000000000
- 109 0000000000000001100000000000
- 110 0000000000000011100000000000
- 111 0000000000000011100000000000
- 112 0000000000000111000000000000
- 113 0000000000000111000000000000
- 114 0000000000000111000000000000
- 115 0000000000000111000000000000
- 116 0000000000000010000000000000
- 117 0000000000000010000000000000
- 118 0000000000000110000000000000
- 119 0000000000000010000000000000
- 120 0000000000000000000000000000
- 121 0000000000000000000000000000
- 122 0000000000000000000000000000
- 123 0000000000000000000000000000
- 124 0000000000000000000000000000
- 125 0000000000000000000000000000
126
127 … all other iterations goes here … 128
- 129 class 9:
- 130 0000000000000000000000000000
- 131 0000000000000000000000000000
- 132 0000000000000000000000000000
- 133 0000000000000000000000000000
- 134 0000000000000001110000000000
- 135 0000000000000011110000000000
- 136 0000000000000011110000000000
- 137 0000000000000111000000000000
- 138 0000000000000110000000000000
- 139 0000000000001100000000000000
- 140 0000000000001100000000000000
- 141 0000000000011100000000000000
- 142 0000000000011100000000000000
- 143 0000000000011000100000000000
- 144 0000000000111001111000000000
- 145 0000000000110000111000000000
- 146 0000000000110000011000000000
- 147 0000000000110000011000000000
- 148 0000000000110000111000000000
- 149 0000000000110001111000000000
- 150 0000000000111111110000000000
- 151 0000000000111111100000000000
- 152 0000000000011110000000000000
- 153 0000000000000000000000000000
- 154 0000000000000000000000000000
- 155 0000000000000000000000000000
- 156 0000000000000000000000000000
- 157 0000000000000000000000000000
158
159 No.ofIteration:10,Difference:19.89546432548733 160
161
162
163
- 164 labeled class 0:
- 165 0000000000000000000000000000
- 166 0000000000000000000000000000
- 167 0000000000000000000000000000
- 168 0000000000000000000000000000
- 169 0000000000000000000000000000
- 170 0000000000000111110000000000
- 171 0000000000011111111000000000
- 172 0000000000111111111110000000
- 173 0000000001111111111110000000
- 174 0000000011111000000111000000
- 175 0000000011110000000011100000
- 176 0000000111100000000011100000
- 177 0000000111000000000001100000
- 178 0000001111000000000001110000
- 179 0000001110000000000001110000
- 180 0000001110000000000001110000
- 181 0000001110000000000011100000
- 182 0000001110000000000011100000
- 183 0000001110000000000111000000
- 184 0000001111000000001111000000
- 185 0000000111100000111110000000
- 186 0000000011111111111100000000
- 187 0000000001111111110000000000
- 188 0000000000011111000000000000
- 189 0000000000000000000000000000
- 190 0000000000000000000000000000
- 191 0000000000000000000000000000
- 192 0000000000000000000000000000
193
- 194 labeled class 1:
- 195 0000000000000000000000000000
- 196 0000000000000000000000000000
- 197 0000000000000000000000000000
- 198 0000000000000000000000000000
- 199 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
- 212 0000000000001110000000000000
- 213 0000000000001110000000000000
- 214 0000000000001110000000000000
- 215 0000000000001110000000000000
- 216 0000000000001100000000000000
- 217 0000000000000000000000000000
- 218 0000000000000000000000000000
- 219 0000000000000000000000000000
- 220 0000000000000000000000000000
- 221 0000000000000000000000000000
- 222 0000000000000000000000000000
223
224 … all other labeled imagination of numbers goes here … 225
- 226 labeledclass9:
- 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 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




