module Svm: sig
.. end
SVM problem and model
module Problem: sig
.. end
module Model: sig
.. end
SVM training
val train : ?svm_type:[ `C_SVC | `EPSILON_SVR | `NU_SVC | `NU_SVR | `ONE_CLASS ] ->
?kernel:[ `LINEAR | `POLY | `PRECOMPUTED | `RBF | `SIGMOID ] ->
?degree:int ->
?gamma:float ->
?coef0:float ->
?c:float ->
?nu:float ->
?eps:float ->
?cachesize:float ->
?tol:float ->
?shrinking:[ `off | `on ] ->
?probability:bool ->
?weights:(int * float) list ->
?verbose:bool -> Problem.t -> Model.t
train params problem
trains a SVM model on the given
problem
and
parameters
params
:
svm_type
- type of SVM classification/regression (default C_SVC
)
kernel
- type of the SVM kernel (default RBF
)
degree
- the exponent in the POLY
kernel (default 3)
gamma
- parameter for POLY
, RBF
and SIGMOID
kernel (default 0)
coef0
- parameter for POLY
and SIGMOID
kernel (default 0)
c
- the cost of constraints violation in C_SVC
, EPSILON_SVR
, and
NU_SVR
(default 1)
nu
- the parameter in NU_SVM
, NU_SVR
and ONE_CLASS
(default 0.5)
eps
- the epsilon in the epsilon-sensitive loss function of
EPSILON_SVR
(default 0.1)
cachesize
- the size of the kernel cache in megabytes (default 100)
tol
- the stopping criterion (default 1e-3)
shrinking
- use on
to conduct shrinking, otherwise off
(default on
)
probability
- if probability = true, then a model with probability
information will be obtained (default false)
weights
- weights to penalize classes (default = [])
verbose
- if verbose = true, then train the SVM in verbose mode
(default false)
Raises Failure
if parameters are not feasible.
Returns the trained model.
val cross_validation : ?svm_type:[ `C_SVC | `EPSILON_SVR | `NU_SVC | `NU_SVR | `ONE_CLASS ] ->
?kernel:[ `LINEAR | `POLY | `PRECOMPUTED | `RBF | `SIGMOID ] ->
?degree:int ->
?gamma:float ->
?coef0:float ->
?c:float ->
?nu:float ->
?eps:float ->
?cachesize:float ->
?tol:float ->
?shrinking:[ `off | `on ] ->
?probability:bool ->
?weights:(int * float) list ->
?verbose:bool -> n_folds:int -> Problem.t -> Lacaml.D.vec
cross_validation params problem n_folds
conducts n-fold
cross-validation on the given problem
and parameters params
.
The parameters params
are the same as in train
above.
Raises Failure
if parameters are not feasible.
Returns vector with all predicted values (of all problem instances) in
the validation process.
SVM prediction
val predict_one : Model.t -> x:Lacaml.D.vec -> float
predict_one model x
does classification or regression on a test vector
x
given a model
.
For a classification model, the predicted class for x
is returned.
For a regression model, the function value of x
is returned.
For a one-class model, +1 or -1 is returned.
val predict : Model.t -> x:Lacaml.D.mat -> Lacaml.D.vec
predict model x
applies predict_one to each row of the matrix x
.
val predict_values : Model.t -> x:Lacaml.D.vec -> float array array
predict_values model x
Returns a matrix with decision values on a test
vector x
.
val predict_probability : Model.t -> x:Lacaml.D.vec -> float * float array
predict_probability m x
does classification or regression on a test
vector x
based on a model
with probability information.
Raises Invalid_argument
if the model does not support probability
estimates.
val predict_from_file : Model.t ->
string -> [ `Expected of Lacaml.D.vec ] * [ `Predicted of Lacaml.D.vec ]
predict_from_file model filename
does classification or regression
on the testing data given in filename
.
Raises Failure
if an error occured during parsing of filename
.
Returns a pair vectors containing the expected (true) values form the
test file and the predicted ones computed from the given model
.