===========
There are two levels of usage. The high-level one uses utility functions
-in linearutil.py and the usage is the same as the LIBLINEAR MATLAB interface.
+in liblinearutil.py and the usage is the same as the LIBLINEAR MATLAB interface.
->>> from linearutil import *
+>>> from liblinearutil import *
# Read data in LIBSVM format
>>> y, x = svm_read_problem('../heart_scale')
>>> m = train(y[:200], x[:200], '-c 4')
# Getting online help
>>> help(train)
-The low-level use directly calls C interfaces imported by linear.py. Note that
+The low-level use directly calls C interfaces imported by liblinear.py. Note that
all arguments and return values are in ctypes format. You need to handle them
carefully.
->>> from linear import *
+>>> from liblinear import *
>>> prob = problem([1,-1], [{1:1, 3:1}, {1:-1,3:-1}])
>>> param = parameter('-c 4')
>>> m = liblinear.train(prob, param) # m is a ctype pointer to a model
Design Description
==================
-There are two files linear.py and linearutil.py, which respectively correspond to
+There are two files liblinear.py and liblinearutil.py, which respectively correspond to
low-level and high-level use of the interface.
-In linear.py, we adopt the Python built-in library "ctypes," so that
+In liblinear.py, we adopt the Python built-in library "ctypes," so that
Python can directly access C structures and interface functions defined
in linear.h.
-While advanced users can use structures/functions in linear.py, to
-avoid handling ctypes structures, in linearutil.py we provide some easy-to-use
+While advanced users can use structures/functions in liblinear.py, to
+avoid handling ctypes structures, in liblinearutil.py we provide some easy-to-use
functions. The usage is similar to LIBLINEAR MATLAB interface.
Data Structures
Before using the data structures, execute the following command to load the
LIBLINEAR shared library:
- >>> from linear import *
+ >>> from liblinear import *
- class feature_node:
Note that the returned structure of interface functions
liblinear.train and liblinear.load_model is a ctypes pointer of
model, which is different from the model object returned
- by train and load_model in linearutil.py. We provide a
+ by train and load_model in liblinearutil.py. We provide a
function toPyModel for the conversion:
>>> model_ptr = liblinear.train(prob, param)
To use utility functions, type
- >>> from linearutil import *
+ >>> from liblinearutil import *
The above command loads
train() : train an linear model
# Construct constants
SOLVER_TYPE = ['L2R_LR', 'L2R_L2LOSS_SVC_DUAL', 'L2R_L2LOSS_SVC', 'L2R_L1LOSS_SVC_DUAL',\
- 'MCSVM_CS', 'L1R_L2LOSS_SVC', 'L1R_LR']
+ 'MCSVM_CS', 'L1R_L2LOSS_SVC', 'L1R_LR', 'L2R_LR_DUAL']
for i, s in enumerate(SOLVER_TYPE): exec("%s = %d" % (s , i))
PRINT_STRING_FUN = CFUNCTYPE(None, c_char_p)
if self.eps == float('inf'):
if self.solver_type in [L2R_LR, L2R_L2LOSS_SVC]:
self.eps = 0.01
- elif self.solver_type in [L2R_L2LOSS_SVC_DUAL, L2R_L1LOSS_SVC_DUAL, MCSVM_CS]:
+ elif self.solver_type in [L2R_L2LOSS_SVC_DUAL, L2R_L1LOSS_SVC_DUAL, MCSVM_CS, L2R_LR_DUAL]:
self.eps = 0.1
elif self.solver_type in [L1R_L2LOSS_SVC, L1R_LR]:
self.eps = 0.01
#!/usr/bin/env python
-from linear import *
+from liblinear import *
def svm_read_problem(data_file_name):
"""
'options':
-s type : set type of solver (default 1)
- 0 -- L2-regularized logistic regression
+ 0 -- L2-regularized logistic regression (primal)
1 -- L2-regularized L2-loss support vector classification (dual)
2 -- L2-regularized L2-loss support vector classification (primal)
3 -- L2-regularized L1-loss support vector classification (dual)
4 -- multi-class support vector classification by Crammer and Singer
5 -- L1-regularized L2-loss support vector classification
6 -- L1-regularized logistic regression
+ 7 -- L2-regularized logistic regression (dual)
-c cost : set the parameter C (default 1)
-e epsilon : set tolerance of termination criterion
-s 0 and 2
|f'(w)|_2 <= eps*min(pos,neg)/l*|f'(w0)|_2,
where f is the primal function, (default 0.01)
- -s 1, 3, and 4
+ -s 1, 3, 4, and 7
Dual maximal violation <= eps; similar to liblinear (default 0.1)
-s 5 and 6
|f'(w)|_inf <= eps*min(pos,neg)/l*|f'(w0)|_inf,