| 234 | self.weight_label[i] = weight_label[i] |
| 235 | |
| 236 | class svm_model(Structure): |
| 237 | _names = ['param', 'nr_class', 'l', 'SV', 'sv_coef', 'rho', |
| 238 | 'probA', 'probB', 'sv_indices', 'label', 'nSV', 'free_sv'] |
| 239 | _types = [svm_parameter, c_int, c_int, POINTER(POINTER(svm_node)), |
| 240 | POINTER(POINTER(c_double)), POINTER(c_double), |
| 241 | POINTER(c_double), POINTER(c_double), POINTER(c_int), |
| 242 | POINTER(c_int), POINTER(c_int), c_int] |
| 243 | _fields_ = genFields(_names, _types) |
| 244 | |
| 245 | def __init__(self): |
| 246 | self.__createfrom__ = 'python' |
| 247 | |
| 248 | def __del__(self): |
| 249 | # free memory created by C to avoid memory leak |
| 250 | if hasattr(self, '__createfrom__') and self.__createfrom__ == 'C': |
| 251 | libsvm.svm_free_and_destroy_model(pointer(self)) |
| 252 | |
| 253 | def get_svm_type(self): |
| 254 | return libsvm.svm_get_svm_type(self) |
| 255 | |
| 256 | def get_nr_class(self): |
| 257 | return libsvm.svm_get_nr_class(self) |
| 258 | |
| 259 | def get_svr_probability(self): |
| 260 | return libsvm.svm_get_svr_probability(self) |
| 261 | |
| 262 | def get_labels(self): |
| 263 | nr_class = self.get_nr_class() |
| 264 | labels = (c_int * nr_class)() |
| 265 | libsvm.svm_get_labels(self, labels) |
| 266 | return labels[:nr_class] |
| 267 | |
| 268 | def get_sv_indices(self): |
| 269 | total_sv = self.get_nr_sv() |
| 270 | sv_indices = (c_int * total_sv)() |
| 271 | libsvm.svm_get_sv_indices(self, sv_indices) |
| 272 | return sv_indices[:total_sv] |
| 273 | |
| 274 | def get_nr_sv(self): |
| 275 | return libsvm.svm_get_nr_sv(self) |
| 276 | |
| 277 | def is_probability_model(self): |
| 278 | return (libsvm.svm_check_probability_model(self) == 1) |
| 279 | |
| 280 | def get_sv_coef(self): |
| 281 | return [tuple(self.sv_coef[j][i] for j in xrange(self.nr_class - 1)) |
| 282 | for i in xrange(self.l)] |
| 283 | |
| 284 | def get_SV(self): |
| 285 | result = [] |
| 286 | for sparse_sv in self.SV[:self.l]: |
| 287 | row = dict() |
| 288 | |
| 289 | i = 0 |
| 290 | while True: |
| 291 | row[sparse_sv[i].index] = sparse_sv[i].value |
| 292 | if sparse_sv[i].index == -1: |
| 293 | break |
nothing calls this directly
no test coverage detected
searching dependent graphs…