SVM is a popular method for classification, regression and distribution estimation that can learn a problem in a higher dimensional space through the use of a kernel trick.
Orange interfaces the libsvm-8.1 library (Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support vector machines, 2001. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm)
witch supports:
- C support vector classification (C_SVC)
- NU support vector classification (NU_SVC)
- ONE CLASS distribution estimation (ONE_CLASS)
- EPSILON support vector regression (EPSILON_SVR)
- NU support vector regression (NU_SVR)
Additionally you can use the following kernel functions:
- linear: u'*v
- polynomial: (gamma*u'*v + coef0)^degree
- radial basis function: exp(-gamma*|u-v|^2)
- sigmoid: tanh(gamma*u'*v + coef0)
- custom kernel (any function that remotely resembles a distance measure between two examples that can be implemented in python)
SVMLearner
SVMLearner class constructs a SVMClassifier
Attributes
- svm_type
- Defines the type of SVM (can be SVMLearner.C_SVC (default), SVMLearner.NU_SVC, SVMLearner.ONE_CLASS, SVMLearner.EPSILON_SVR, SVMLearner.NU_SVR)
- kernel_type
- Defines the type of a kernel to use for learning (can be SVMLearner.RBF (default), SVMLearner.LINEAR, SVMLearner.POLY, SVMLearner.SIGMOID, SVMLearner.CUSTOM)
- degree
- Kernel parameter (POLY) (default 3)
- gamma
- Kernel parameter (POLY/RBF/SIGMOID) (default 1.0/number_of_examples)
- coef0
- Kernel parameter (POLY/SIGMOID) (default 0)
- kernelFunc
- Function that will be called if
kernel_type
is SVMLearner.CUSTOM. It must accept two orange.Example arguments and return a float.
- C
- C parameter for C_SVC, EPSILON_SVR, NU_SVR
- nu
- Nu parameter for NU_SVC, NU_SVR and ONE_CLASS (default 0.5)
- p
- Epsilon in loss-function for EPSILON_SVR
- cache_size
- Cache memory size in MB (default 100)
- eps
- Tolerance of termination criterion (default 0.001)
- shrinking
- Determines whether to use shrinking heuristics (default True)
- probability
- Determines if a probability model should be build (default False)
SVMLearnerSparse
Same as above except that it learns from the examples mata attributes. Note that meta attributes dont need to be registerd with the dataset domain, or present in all the examples.
Use this if you are using large sparse datasets.
SVMClassifier
Classifier used for classification, regression or distribution estimation (ONE_CLASS). In the later case the return value of the __call__ function can be 1.0 (positive case) or -1.0(negative case).
For a multiclass classification problem with k classes there are k*(k-1)/2 1class vs. 1class internal binary classifiers being build. The multiclass classification is then performed by a majority vote.
Attributes
- examples
- Holds the examples used for training
- supportVectors
- Holds the support vectors. They are listed in the order of their classes (i.e. they are grouped by the order of classes as they apear in the domains
classVar.values
)
- nSV
- Number of support vectors for each class (the same order as above)
- rho
- Constants in decision functions in the order of 1v2, 1v3, ... 1vsN, 2vs3, 2vs4, ...
- coef
- Coefficients for support vectors in decision functions (coef[nClass-1][nSupportVectors]). If k is the total number of classes then, for each support vector there are k-1 coefficients y*alpha where alpha are dual solution of the following two class problems: 1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k; and y=1 in first j-1 coefficients, y=-1 in the remaining k-j coefficients
Methods
- getDecisionValues(example)
- Return the decision values of all nClass*(nClass-1)/2 internal binary classifiers in the order of 1v2, 1v3, ... 1vsN, 2vs3, 2vs4, ...
Examples
>>> import orange
>>> data=orange.ExampleTable("iris.tab")
>>> l=orange.SVMLearner()
>>> l.svm_type=orange.SVMLearner.NU_SVC
>>> l.nu=0.3
>>> l.probability=True
>>> c=l(data)
>>> for e in data:
... print e[-1], c(e), c(e, c.GetProbabilities)
...
Iris-setosa Iris-setosa <0.971, 0.015, 0.014>
Iris-setosa Iris-setosa <0.964, 0.019, 0.016>
Iris-setosa Iris-setosa <0.968, 0.016, 0.016>
...