From 308fbe41754758a669a9695fe22e0e774b5cab5f Mon Sep 17 00:00:00 2001 From: Juan Pasutti Date: Wed, 18 Sep 2024 00:58:39 -0300 Subject: [PATCH] Add doctest to _rbf Kernel func --- machine_learning/sequential_minimum_optimization.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/machine_learning/sequential_minimum_optimization.py b/machine_learning/sequential_minimum_optimization.py index eaf307a39554..994abf0d61d1 100644 --- a/machine_learning/sequential_minimum_optimization.py +++ b/machine_learning/sequential_minimum_optimization.py @@ -471,6 +471,13 @@ def _linear(self, v1, v2): return np.inner(v1, v2) + self.coef0 def _rbf(self, v1, v2): + """ + >>> from machine_learning.sequential_minimum_optimization import Kernel + >>> kernel = Kernel(kernel='linear') + >>> result = kernel._rbf(np.array([1, 2]), np.array([2, 3])) + >>> round(result, 3) + 0.135 + """ return np.exp(-1 * (self.gamma * np.linalg.norm(v1 - v2) ** 2)) def _check(self):