EpsilonSVR
EpsilonSVR
A model type for constructing a ϵ-support vector regressor, based on LIBSVM.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
EpsilonSVR = @load EpsilonSVR pkg=LIBSVM
Do model = EpsilonSVR()
to construct an instance with default hyper-parameters. Provide keyword arguments to override hyper-parameter defaults, as in EpsilonSVR(kernel=...)
.
Reference for algorithm and core C-library: C.-C. Chang and C.-J. Lin (2011): "LIBSVM: a library for support vector machines." ACM Transactions on Intelligent Systems and Technology, 2(3):27:1–27:27. Updated at https://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf.
This model is an adaptation of the classifier SVC
to regression, but has an additional parameter epsilon
(denoted $ϵ$ in the cited reference).
Training data
In MLJ or MLJBase, bind an instance model
to data with:
mach = machine(model, X, y)
where
X
: any table of input features (eg, aDataFrame
) whose columns each haveContinuous
element scitype; check column scitypes withschema(X)
y
: is the target, which can be anyAbstractVector
whose element scitype isContinuous
; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...)
.
Hyper-parameters
kernel=LIBSVM.Kernel.RadialBasis
: either an object that can be called, as inkernel(x1, x2)
, or one of the built-in kernels from the LIBSVM.jl package listed below. Herex1
andx2
are vectors whose lengths match the number of columns of the training dataX
(see "Examples" below).LIBSVM.Kernel.Linear
:(x1, x2) -> x1'*x2
LIBSVM.Kernel.Polynomial
:(x1, x2) -> gamma*x1'*x2 + coef0)^degree
LIBSVM.Kernel.RadialBasis
:(x1, x2) -> (exp(-gamma*norm(x1 - x2)^2))
LIBSVM.Kernel.Sigmoid
:(x1, x2) - > tanh(gamma*x1'*x2 + coef0)
Here
gamma
,coef0
,degree
are other hyper-parameters. Serialization of models with user-defined kernels comes with some restrictions. See LIVSVM.jl issue91gamma = 0.0
: kernel parameter (see above); ifgamma==-1.0
thengamma = 1/nfeatures
is used in training, wherenfeatures
is the number of features (columns ofX
). Ifgamma==0.0
thengamma = 1/(var(Tables.matrix(X))*nfeatures)
is used. Actual value used appears in the report (see below).coef0 = 0.0
: kernel parameter (see above)degree::Int32 = Int32(3)
: degree in polynomial kernel (see above)cost=1.0
(range (0,Inf
)): the parameter denoted $C$ in the cited reference; for greater regularization, decreasecost
epsilon=0.1
(range (0,Inf
)): the parameter denoted $ϵ$ in the cited reference;epsilon
is the thickness of the penalty-free neighborhood of the graph of the prediction function ("slab" or "tube"). Specifically, a data point(x, y)
incurs no training loss unless it is outside this neighborhood; the further away it is from the this neighborhood, the greater the loss penalty.cachesize=200.0
cache memory size in MBtolerance=0.001
: tolerance for the stopping criterionshrinking=true
: whether to use shrinking heuristics
Operations
predict(mach, Xnew)
: return predictions of the target given featuresXnew
having the same scitype asX
above.
Fitted parameters
The fields of fitted_params(mach)
are:
libsvm_model
: the trained model object created by the LIBSVM.jl package
Report
The fields of report(mach)
are:
gamma
: actual value of the kernel parametergamma
used in training
Examples
Using a built-in kernel
using MLJ
import LIBSVM
EpsilonSVR = @load EpsilonSVR pkg=LIBSVM ## model type
model = EpsilonSVR(kernel=LIBSVM.Kernel.Polynomial) ## instance
X, y = make_regression(rng=123) ## table, vector
mach = machine(model, X, y) |> fit!
Xnew, _ = make_regression(3, rng=123)
julia> yhat = predict(mach, Xnew)
3-element Vector{Float64}:
0.2512132502584155
0.007340201523624579
-0.2482949812264707
User-defined kernels
k(x1, x2) = x1'*x2 ## equivalent to `LIBSVM.Kernel.Linear`
model = EpsilonSVR(kernel=k)
mach = machine(model, X, y) |> fit!
julia> yhat = predict(mach, Xnew)
3-element Vector{Float64}:
1.1121225361666656
0.04667702229741916
-0.6958148424680672
See also NuSVR
, LIVSVM.jl and the original C implementation documentation.