(
self,
*,
regularization: float = np.inf,
kernel: str = "linear",
gamma: float = 0.0,
)
| 52 | """ |
| 53 | |
| 54 | def __init__( |
| 55 | self, |
| 56 | *, |
| 57 | regularization: float = np.inf, |
| 58 | kernel: str = "linear", |
| 59 | gamma: float = 0.0, |
| 60 | ) -> None: |
| 61 | self.regularization = regularization |
| 62 | self.gamma = gamma |
| 63 | if kernel == "linear": |
| 64 | self.kernel = self.__linear |
| 65 | elif kernel == "rbf": |
| 66 | if self.gamma == 0: |
| 67 | raise ValueError("rbf kernel requires gamma") |
| 68 | if not isinstance(self.gamma, (float, int)): |
| 69 | raise ValueError("gamma must be float or int") |
| 70 | if not self.gamma > 0: |
| 71 | raise ValueError("gamma must be > 0") |
| 72 | self.kernel = self.__rbf |
| 73 | # in the future, there could be a default value like in sklearn |
| 74 | # sklear: def_gamma = 1/(n_features * X.var()) (wiki) |
| 75 | # previously it was 1/(n_features) |
| 76 | else: |
| 77 | msg = f"Unknown kernel: {kernel}" |
| 78 | raise ValueError(msg) |
| 79 | |
| 80 | # kernels |
| 81 | def __linear(self, vector1: ndarray, vector2: ndarray) -> float: |
nothing calls this directly
no outgoing calls
no test coverage detected