svm_read_problem(data_file_name) -> [y, x] Read LIBSVM-format data from data_file_name and return labels y and data instances x.
(data_file_name)
| 6 | sys.path = [os.path.dirname(os.path.abspath(__file__))] + sys.path |
| 7 | |
| 8 | def svm_read_problem(data_file_name): |
| 9 | """ |
| 10 | svm_read_problem(data_file_name) -> [y, x] |
| 11 | |
| 12 | Read LIBSVM-format data from data_file_name and return labels y |
| 13 | and data instances x. |
| 14 | """ |
| 15 | prob_y = [] |
| 16 | prob_x = [] |
| 17 | for line in open(data_file_name): |
| 18 | line = line.split(None, 1) |
| 19 | # In case an instance with all zero features |
| 20 | if len(line) == 1: line += [''] |
| 21 | label, features = line |
| 22 | xi = {} |
| 23 | for e in features.split(): |
| 24 | ind, val = e.split(":") |
| 25 | xi[int(ind)] = float(val) |
| 26 | prob_y += [float(label)] |
| 27 | prob_x += [xi] |
| 28 | return (prob_y, prob_x) |
| 29 | |
| 30 | def svm_load_model(model_file_name): |
| 31 | """ |