(self, path)
| 411 | thundersvm.save_to_file_scikit(c_void_p(self.model), path.encode('utf-8')) |
| 412 | |
| 413 | def load_from_file(self, path): |
| 414 | if self.model is None: |
| 415 | thundersvm.model_new.restype = c_void_p |
| 416 | self.model = thundersvm.model_new(SVM_TYPE.index(self._impl)) |
| 417 | if self.max_mem_size != -1: |
| 418 | thundersvm.set_memory_size(c_void_p(self.model), self.max_mem_size) |
| 419 | thundersvm.load_from_file_scikit(c_void_p(self.model), path.encode('utf-8')) |
| 420 | degree = (c_int * 1)() |
| 421 | gamma = (c_float * 1)() |
| 422 | coef0 = (c_float * 1)() |
| 423 | probability = (c_int * 1)() |
| 424 | kernel = (c_char * 20)() |
| 425 | thundersvm.init_model_param(kernel, degree, gamma, |
| 426 | coef0, probability, c_void_p(self.model)) |
| 427 | n_classes = (c_int * 1)() |
| 428 | thundersvm.get_n_classes(c_void_p(self.model), n_classes) |
| 429 | self.n_classes = n_classes[0] |
| 430 | n_support_ = (c_int * self.n_classes)() |
| 431 | thundersvm.get_support_classes(n_support_, self.n_classes, c_void_p(self.model)) |
| 432 | self.n_support_ = np.frombuffer(n_support_, dtype=np.int32).astype(int) |
| 433 | self.n_sv = thundersvm.n_sv(c_void_p(self.model)) |
| 434 | |
| 435 | n_feature = (c_int * 1)() |
| 436 | thundersvm.get_sv_max_index(c_void_p(self.model), n_feature) |
| 437 | self.n_features = n_feature[0] |
| 438 | csr_row = (c_int * (self.n_sv + 1))() |
| 439 | csr_col = (c_int * (self.n_sv * self.n_features))() |
| 440 | csr_data = (c_float * (self.n_sv * self.n_features))() |
| 441 | data_size = (c_int * 1)() |
| 442 | sv_indices = (c_int * self.n_sv)() |
| 443 | thundersvm.get_sv(csr_row, csr_col, csr_data, data_size, sv_indices, c_void_p(self.model)) |
| 444 | self.row = np.frombuffer(csr_row, dtype=np.int32) |
| 445 | self.col = np.frombuffer(csr_col, dtype=np.int32)[:data_size[0]] |
| 446 | self.data = np.frombuffer(csr_data, dtype=np.float32)[:data_size[0]] |
| 447 | self.support_vectors_ = sp.csr_matrix((self.data, self.col, self.row)) |
| 448 | # if self._sparse == False: |
| 449 | # self.support_vectors_ = self.support_vectors_.toarray(order = 'C') |
| 450 | self.support_ = np.frombuffer(sv_indices, dtype=np.int32) |
| 451 | dual_coef = (c_float * ((self.n_classes - 1) * self.n_sv))() |
| 452 | thundersvm.get_coef(dual_coef, self.n_classes, self.n_sv, c_void_p(self.model)) |
| 453 | self.dual_coef_ = np.frombuffer(dual_coef, dtype=np.float32)\ |
| 454 | .astype(float)\ |
| 455 | .reshape((self.n_classes - 1, self.n_sv)) |
| 456 | |
| 457 | rho_size = int(self.n_classes * (self.n_classes - 1) / 2) |
| 458 | self.n_binary_model = rho_size |
| 459 | rho = (c_float * rho_size)() |
| 460 | thundersvm.get_rho(rho, rho_size, c_void_p(self.model)) |
| 461 | self.intercept_ = np.frombuffer(rho, dtype=np.float32).astype(float) |
| 462 | |
| 463 | # if self.kernel == 'linear': |
| 464 | # coef = (c_float * (self.n_binary_model * self.n_sv))() |
| 465 | # thundersvm.get_linear_coef(coef, self.n_binary_model, self.n_features, c_void_p(self.model)) |
| 466 | # self.coef_ = np.array([coef[index] for index in range(0, self.n_binary_model * self.n_features)]).astype(float) |
| 467 | # self.coef_ = np.reshape(self.coef_, (self.n_binary_model, self.n_features)) |
| 468 | |
| 469 | self.kernel = kernel.value |
| 470 | self.degree = degree[0] |
nothing calls this directly
no test coverage detected