(self, options)
| 168 | self.print_func = None |
| 169 | |
| 170 | def parse_options(self, options): |
| 171 | if isinstance(options, list): |
| 172 | argv = options |
| 173 | elif isinstance(options, str): |
| 174 | argv = options.split() |
| 175 | else: |
| 176 | raise TypeError("arg 1 should be a list or a str.") |
| 177 | self.set_to_default_values() |
| 178 | self.print_func = cast(None, PRINT_STRING_FUN) |
| 179 | weight_label = [] |
| 180 | weight = [] |
| 181 | |
| 182 | i = 0 |
| 183 | while i < len(argv) : |
| 184 | if argv[i] == "-s": |
| 185 | i = i + 1 |
| 186 | self.solver_type = int(argv[i]) |
| 187 | elif argv[i] == "-c": |
| 188 | i = i + 1 |
| 189 | self.C = float(argv[i]) |
| 190 | elif argv[i] == "-p": |
| 191 | i = i + 1 |
| 192 | self.p = float(argv[i]) |
| 193 | elif argv[i] == "-e": |
| 194 | i = i + 1 |
| 195 | self.eps = float(argv[i]) |
| 196 | elif argv[i] == "-B": |
| 197 | i = i + 1 |
| 198 | self.bias = float(argv[i]) |
| 199 | elif argv[i] == "-v": |
| 200 | i = i + 1 |
| 201 | self.cross_validation = 1 |
| 202 | self.nr_fold = int(argv[i]) |
| 203 | if self.nr_fold < 2 : |
| 204 | raise ValueError("n-fold cross validation: n must >= 2") |
| 205 | elif argv[i].startswith("-w"): |
| 206 | i = i + 1 |
| 207 | self.nr_weight += 1 |
| 208 | nr_weight = self.nr_weight |
| 209 | weight_label += [int(argv[i-1][2:])] |
| 210 | weight += [float(argv[i])] |
| 211 | elif argv[i] == "-q": |
| 212 | self.print_func = PRINT_STRING_FUN(print_null) |
| 213 | else : |
| 214 | raise ValueError("Wrong options") |
| 215 | i += 1 |
| 216 | |
| 217 | liblinear.set_print_string_function(self.print_func) |
| 218 | self.weight_label = (c_int*self.nr_weight)() |
| 219 | self.weight = (c_double*self.nr_weight)() |
| 220 | for i in range(self.nr_weight): |
| 221 | self.weight[i] = weight[i] |
| 222 | self.weight_label[i] = weight_label[i] |
| 223 | |
| 224 | if self.eps == float('inf'): |
| 225 | if self.solver_type in [L2R_LR, L2R_L2LOSS_SVC]: |
| 226 | self.eps = 0.01 |
| 227 | elif self.solver_type in [L2R_L2LOSS_SVR]: |
no test coverage detected