predict(y, x, m [, options]) -> (p_labels, p_acc, p_vals) Predict data (y, x) with the SVM model m. options: -b probability_estimates: whether to output probability estimates, 0 or 1 (default 0); currently for logistic regression only -q quiet mode (no outputs) The return tuple cont
(y, x, m, options="")
| 163 | return m |
| 164 | |
| 165 | def predict(y, x, m, options=""): |
| 166 | """ |
| 167 | predict(y, x, m [, options]) -> (p_labels, p_acc, p_vals) |
| 168 | |
| 169 | Predict data (y, x) with the SVM model m. |
| 170 | options: |
| 171 | -b probability_estimates: whether to output probability estimates, 0 or 1 (default 0); currently for logistic regression only |
| 172 | -q quiet mode (no outputs) |
| 173 | |
| 174 | The return tuple contains |
| 175 | p_labels: a list of predicted labels |
| 176 | p_acc: a tuple including accuracy (for classification), mean-squared |
| 177 | error, and squared correlation coefficient (for regression). |
| 178 | p_vals: a list of decision values or probability estimates (if '-b 1' |
| 179 | is specified). If k is the number of classes, for decision values, |
| 180 | each element includes results of predicting k binary-class |
| 181 | SVMs. if k = 2 and solver is not MCSVM_CS, only one decision value |
| 182 | is returned. For probabilities, each element contains k values |
| 183 | indicating the probability that the testing instance is in each class. |
| 184 | Note that the order of classes here is the same as 'model.label' |
| 185 | field in the model structure. |
| 186 | """ |
| 187 | |
| 188 | def info(s): |
| 189 | print(s) |
| 190 | |
| 191 | predict_probability = 0 |
| 192 | argv = options.split() |
| 193 | i = 0 |
| 194 | while i < len(argv): |
| 195 | if argv[i] == '-b': |
| 196 | i += 1 |
| 197 | predict_probability = int(argv[i]) |
| 198 | elif argv[i] == '-q': |
| 199 | info = print_null |
| 200 | else: |
| 201 | raise ValueError("Wrong options") |
| 202 | i+=1 |
| 203 | |
| 204 | solver_type = m.param.solver_type |
| 205 | nr_class = m.get_nr_class() |
| 206 | nr_feature = m.get_nr_feature() |
| 207 | is_prob_model = m.is_probability_model() |
| 208 | bias = m.bias |
| 209 | if bias >= 0: |
| 210 | biasterm = feature_node(nr_feature+1, bias) |
| 211 | else: |
| 212 | biasterm = feature_node(-1, bias) |
| 213 | pred_labels = [] |
| 214 | pred_values = [] |
| 215 | |
| 216 | if predict_probability: |
| 217 | if not is_prob_model: |
| 218 | raise TypeError('probability output is only supported for logistic regression') |
| 219 | prob_estimates = (c_double * nr_class)() |
| 220 | for xi in x: |
| 221 | xi, idx = gen_feature_nodearray(xi, feature_max=nr_feature) |
| 222 | xi[-2] = biasterm |
nothing calls this directly
no test coverage detected
searching dependent graphs…