]> granicus.if.org Git - liblinear/commitdiff
Changes due to a bug of the same file in LIBSVM:
authorppetter1025 <peter58972@gmail.com>
Mon, 10 Sep 2018 11:50:26 +0000 (19:50 +0800)
committerppetter1025 <peter58972@gmail.com>
Mon, 24 Sep 2018 16:43:57 +0000 (00:43 +0800)
fix a bug in python/commonutil.py for reading pre-computed kernel

python/commonutil.py

index fcc6d24ba7770a1c67e732d52331c0127d46473c..f34b887d7be2f3fec76693c4ce27d1ba40d49dcc 100644 (file)
@@ -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]