From: ppetter1025 Date: Mon, 10 Sep 2018 11:50:26 +0000 (+0800) Subject: Changes due to a bug of the same file in LIBSVM: X-Git-Tag: v221~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7f3615c2d20af1caf1375cc62f93929ec8058ed;p=liblinear Changes due to a bug of the same file in LIBSVM: fix a bug in python/commonutil.py for reading pre-computed kernel --- diff --git a/python/commonutil.py b/python/commonutil.py index fcc6d24..f34b887 100644 --- a/python/commonutil.py +++ b/python/commonutil.py @@ -25,6 +25,7 @@ def svm_read_problem(data_file_name, return_scipy=False): prob_x = [] row_ptr = [0] col_idx = [] + indx_start = 1 for i, line in enumerate(open(data_file_name)): line = line.split(None, 1) # In case an instance with all zero features @@ -35,9 +36,11 @@ def svm_read_problem(data_file_name, return_scipy=False): nz = 0 for e in features.split(): ind, val = e.split(":") + if ind == '0': + indx_start = 0 val = float(val) if val != 0: - col_idx += [int(ind)-1] + col_idx += [int(ind)-indx_start] prob_x += [val] nz += 1 row_ptr += [row_ptr[-1]+nz]