NuSVR
NuSVRA 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
NuSVR = @load NuSVR pkg=LIBSVMDo model = NuSVR() to construct an instance with default hyper-parameters. Provide keyword arguments to override hyper-parameter defaults, as in NuSVR(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 a re-parameterization of EpsilonSVR in which the epsilon hyper-parameter is replaced with a new parameter nu (denoted $ν$ in the cited reference) which attempts to control the number of support vectors directly.
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 haveContinuouselement scitype; check column scitypes withschema(X)y: is the target, which can be anyAbstractVectorwhose 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 in
kernel(x1, x2), or one of the built-in kernels from the LIBSVM.jl package listed below. Herex1andx2are vectors whose lengths match the number of columns of the training dataX(see "Examples" below).LIBSVM.Kernel.Linear:(x1, x2) -> x1'*x2LIBSVM.Kernel.Polynomial:(x1, x2) -> gamma*x1'*x2 + coef0)^degreeLIBSVM.Kernel.RadialBasis:(x1, x2) -> (exp(-gamma*norm(x1 - x2)^2))LIBSVM.Kernel.Sigmoid:(x1, x2) - > tanh(gamma*x1'*x2 + coef0)
Here
gamma,coef0,degreeare 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.0thengamma = 1/nfeaturesis used in training, wherenfeaturesis the number of features (columns ofX). Ifgamma==0.0thengamma = 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, decreasecostnu=0.5(range (0, 1]): An upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. Denoted $ν$ in the cited paper. Changingnuchanges the thickness of some neighborhood of the graph of the prediction function ("tube" or "slab") and a training error is said to occur when a data point(x, y)lies outside of that neighborhood.cachesize=200.0cache 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 featuresXnewhaving the same scitype asXabove.
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 parametergammaused in training
Examples
Using a built-in kernel
using MLJ
import LIBSVM
NuSVR = @load NuSVR pkg=LIBSVM ## model type
model = NuSVR(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.2008156459920009
0.1131520519131709
-0.2076156254934889User-defined kernels
k(x1, x2) = x1'*x2 ## equivalent to `LIBSVM.Kernel.Linear`
model = NuSVR(kernel=k)
mach = machine(model, X, y) |> fit!
julia> yhat = predict(mach, Xnew)
3-element Vector{Float64}:
1.1211558175964662
0.06677125944808422
-0.6817578942749346See also EpsilonSVR, LIVSVM.jl and the original C implementation documentation.