64 lines
1.9 KiB
Plaintext
64 lines
1.9 KiB
Plaintext
|
Introduction
|
||
|
============
|
||
|
|
||
|
This tool provides a Python interface to LIBSVM with instance weight support
|
||
|
|
||
|
Installation
|
||
|
============
|
||
|
|
||
|
Please check README for detail.
|
||
|
|
||
|
USAGE
|
||
|
=====
|
||
|
|
||
|
The usage is bascally the same as the version without supporting
|
||
|
instance weights. We only show differences below.
|
||
|
|
||
|
- Function: svm_train
|
||
|
|
||
|
There are three ways to call svm_train()
|
||
|
|
||
|
>>> model = svm_train(W, y, x [, 'training_options'])
|
||
|
>>> model = svm_train(prob [, 'training_options'])
|
||
|
>>> model = svm_train(prob, param)
|
||
|
|
||
|
W: a list/tuple of l training weights (type must be double).
|
||
|
Use [] if no weights.
|
||
|
|
||
|
y: a list/tuple of l training labels (type must be int/double).
|
||
|
|
||
|
x: a list/tuple of l training instances. The feature vector of
|
||
|
each training instance is an instance of list/tuple or dictionary.
|
||
|
|
||
|
training_options: a string in the same form as that for LIBSVM command
|
||
|
mode.
|
||
|
|
||
|
prob: an svm_problem instance generated by calling
|
||
|
svm_problem(W, y, x).
|
||
|
|
||
|
param: an svm_parameter instance generated by calling
|
||
|
svm_parameter('training_options')
|
||
|
|
||
|
model: the returned svm_model instance. See svm.h for details of this
|
||
|
structure. If '-v' is specified, cross validation is
|
||
|
conducted and the returned model is just a scalar: cross-validation
|
||
|
accuracy for classification and mean-squared error for regression.
|
||
|
|
||
|
To train the same data many times with different
|
||
|
parameters, the second and the third ways should be faster..
|
||
|
|
||
|
Examples:
|
||
|
|
||
|
>>> y, x = svm_read_problem('../heart_scale')
|
||
|
>>> W = [1] * len(y)
|
||
|
>>> W[0] = 10
|
||
|
>>> prob = svm_problem(W, y, x)
|
||
|
>>> param = svm_parameter('-s 3 -c 5 -h 0')
|
||
|
>>> m = svm_train([], y, x, '-c 5')
|
||
|
>>> m = svm_train(W, y, x)
|
||
|
>>> m = svm_train(prob, '-t 2 -c 5')
|
||
|
>>> m = svm_train(prob, param)
|
||
|
>>> CV_ACC = svm_train(W, y, x, '-v 3')
|
||
|
|
||
|
|