|
80 | 80 | "metadata": {}, |
81 | 81 | "outputs": [], |
82 | 82 | "source": [ |
83 | | - "# Labels matrix (), each row representing one class, and the columns represent the true label of each image \n", |
| 83 | + "# Labels matrix, each row representing one class, and the columns represent whether\n", |
| 84 | + "# the image belongs to that class (row index) or not (-1, 1) \n", |
84 | 85 | "T = np.zeros((10, 2400))\n", |
85 | 86 | "for i in range(len(T)):\n", |
86 | 87 | " T[i] = np.where(t == i, 1, -1)\n", |
|
117 | 118 | "metadata": {}, |
118 | 119 | "outputs": [], |
119 | 120 | "source": [ |
120 | | - "out = np.dot(x_delta, WC)\n", |
121 | | - "WC.shape" |
| 121 | + "predictions = np.dot(x_delta, weights_matrix)\n", |
| 122 | + "conf_matrix = np.zeros((10, 10))\n", |
| 123 | + "for i, row in enumerate(predictions):\n", |
| 124 | + " prediction = np.where(row == row.max())[0][0] # The index (class) of the maximum value (most probable class)\n", |
| 125 | + " true_value = t[i]\n", |
| 126 | + " conf_matrix[true_value][prediction] += 1\n", |
| 127 | + " \n", |
| 128 | + "conf_matrix" |
122 | 129 | ] |
123 | 130 | }, |
124 | 131 | { |
|
127 | 134 | "metadata": {}, |
128 | 135 | "outputs": [], |
129 | 136 | "source": [ |
130 | | - "tested = out[1000]\n", |
131 | | - "pred = np.where(zero == zero.max())\n", |
| 137 | + "to_be_tested = predictions[2030]\n", |
| 138 | + "pred = np.where(to_be_tested == to_be_tested.max())\n", |
132 | 139 | "pred, pred[0][0]" |
133 | 140 | ] |
134 | | - }, |
135 | | - { |
136 | | - "cell_type": "code", |
137 | | - "execution_count": null, |
138 | | - "metadata": { |
139 | | - "scrolled": false |
140 | | - }, |
141 | | - "outputs": [], |
142 | | - "source": [ |
143 | | - "out.shape" |
144 | | - ] |
145 | 141 | } |
146 | 142 | ], |
147 | 143 | "metadata": { |
|
0 commit comments