Get the expected class of an observation Args: observation (Vector): observation Returns: int {1, -1}: expected class >>> xs = [ ... np.asarray([0, 1]), np.asarray([0, 2]), ... np.asarray([1, 1]), np.asarray([1, 2])
(self, observation: ndarray)
| 168 | self.offset = s / n |
| 169 | |
| 170 | def predict(self, observation: ndarray) -> int: |
| 171 | """ |
| 172 | Get the expected class of an observation |
| 173 | |
| 174 | Args: |
| 175 | observation (Vector): observation |
| 176 | |
| 177 | Returns: |
| 178 | int {1, -1}: expected class |
| 179 | |
| 180 | >>> xs = [ |
| 181 | ... np.asarray([0, 1]), np.asarray([0, 2]), |
| 182 | ... np.asarray([1, 1]), np.asarray([1, 2]) |
| 183 | ... ] |
| 184 | >>> y = np.asarray([1, 1, -1, -1]) |
| 185 | >>> s = SVC() |
| 186 | >>> s.fit(xs, y) |
| 187 | >>> s.predict(np.asarray([0, 1])) |
| 188 | 1 |
| 189 | >>> s.predict(np.asarray([1, 1])) |
| 190 | -1 |
| 191 | >>> s.predict(np.asarray([2, 2])) |
| 192 | -1 |
| 193 | """ |
| 194 | s = sum( |
| 195 | self.optimum[n] |
| 196 | * self.classes[n] |
| 197 | * self.kernel(self.observations[n], observation) |
| 198 | for n in range(len(self.classes)) |
| 199 | ) |
| 200 | return 1 if s + self.offset >= 0 else -1 |
| 201 | |
| 202 | |
| 203 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected