There are two levels of usage. The high-level one uses utility functions
in liblinearutil.py and the usage is the same as the LIBLINEAR MATLAB interface.
+>>> import numpy as np
>>> import scipy
>>> from liblinear.liblinearutil import *
# Read data in LIBSVM format
# Construct problem in Scipy format
# Dense data: numpy ndarray
->>> import numpy as np
>>> y, x = np.asarray([1,-1]), np.asarray([[1,0,1], [-1,0,-1]])
# Sparse data: scipy csr_matrix((data, (row_ind, col_ind))
>>> y, x = np.asarray([1,-1]), scipy.sparse.csr_matrix(([1, 1, -1, -1], ([0, 0, 1, 1], [0, 2, 0, 2])))
if not n == len(coef):
print("WARNING: The dimension of scaling parameters and feature number do not match.", file=sys.stderr)
- coef = coef.resize(n)
+ coef = coef.resize(n) # zeros padded if n > len(coef)
offset = offset.resize(n)
# scaled_x = x * diag(coef) + ones(l, 1) * offset'