(self, X, y)
| 38 | self.C = C |
| 39 | |
| 40 | def fit(self, X, y): |
| 41 | self.y = y |
| 42 | self.X = X |
| 43 | m, n = X.shape |
| 44 | |
| 45 | # Calculate Kernel |
| 46 | self.K = np.zeros((m, m)) |
| 47 | for i in range(m): |
| 48 | self.K[i, :] = self.kernel(X[i, np.newaxis], self.X) |
| 49 | |
| 50 | # Solve with cvxopt final QP needs to be reformulated |
| 51 | # to match the input form for cvxopt.solvers.qp |
| 52 | P = cvxopt.matrix(np.outer(y, y) * self.K) |
| 53 | q = cvxopt.matrix(-np.ones((m, 1))) |
| 54 | G = cvxopt.matrix(np.vstack((np.eye(m) * -1, np.eye(m)))) |
| 55 | h = cvxopt.matrix(np.hstack((np.zeros(m), np.ones(m) * self.C))) |
| 56 | A = cvxopt.matrix(y, (1, m), "d") |
| 57 | b = cvxopt.matrix(np.zeros(1)) |
| 58 | cvxopt.solvers.options["show_progress"] = False |
| 59 | sol = cvxopt.solvers.qp(P, q, G, h, A, b) |
| 60 | self.alphas = np.array(sol["x"]) |
| 61 | |
| 62 | def predict(self, X): |
| 63 | y_predict = np.zeros((X.shape[0])) |
no outgoing calls
no test coverage detected