Learn R Programming

superml (version 0.2.0)

SVMTrainer: Support Vector Machines Trainer

Description

Trains a support vector machine (svm) model. It is based on the magnificently fast speed liquidSVM R package. It provides a more unified interface over the package retaining all its functionality.

The model is intelligently trained with a default set of hyper parameters. Also, there are inbuilt grid setups which can be easily initialised. It has capability to support batch processing of data to avoid memory errors. It supports binary classification, multi classification, regression models

Usage

SVMTrainer

Format

R6Class object.

Usage

For usage details see Methods, Arguments and Examples sections.

svm = SVMTrainer$new(type=NULL,scale=TRUE, gammas=NULL, lambdas=NULL, c_values=NULL,predict.prob=FALSE,
                     verbose=NULL, ncores=NULL, partition_choice=0,
                     seed=-1, grid_choice=NULL, useCells=FALSE, mc_type=NULL,
                     adaptivity_control=0)
svm$fit(X_train, y_train)
prediction <- svm$predict(X_test)

Methods

$new()

Initialises an instance of svm model

$fit()

fits model to an input train data and trains the model.

$predict()

returns predictions by fitting the trained model on test data.

Arguments

params

for detailed explanation on parameters, refer to original documentation https://cran.r-project.org/package=liquidSVM

type

type of model to train, possible values: "bc" = binary classification, "mc" = multiclassification, "ls" = least square regression, "qt" = quantile regression

scale

normalises the feature between 0 and 1, default = TRUE

gammas

bandwidth of the kernel, default value is chosen from a list of gamma values generated internally

lambdas

regularization parameter

c_values

cost parameter

predict.prob

If TRUE then final prediction is probability else labels. This also restricts the choices of mc_type to c("OvA_ls","AvA_ls").

verbose

display the progress to standard output, possible values are 0, 1

ncores

number of cores to use for parallel processing, possible values are 0 (default), -1

partition_choice

optimization parameter to train on large data sets, possible value are: 0 (disables partitioning) , 6 (high speed), 5 (best error)

seed

random seed, default = -1

grid_choice

internal grid used for convenient hyperparameter tuning of gammas, lambdas, possible values are: 0,1,2,-1,-2

useCells

activates batch processing, set it to TRUE in case of out of memory errors

mc_type

configure multiclassification variant like OnevsAll, AllvsAll, possible values are: "AvA_hinge", "OvA_ls", "OvA_hinge", "AvA_ls"

quantile

do quantile regression, default=FALSE

weights

weights to be used in quantile regression, default is c(0.05, 0.1, 0.5, 0.9, 0.95)

Examples

Run this code
# NOT RUN {
data(iris)
## Multiclassification
svm <- SVMTrainer$new(type="mc")
svm$fit(iris, "Species")
p <- svm$predict(iris)

## Least Squares
svm <- SVMTrainer$new(type="ls")
svm$fit(trees, "Height")
p <- svm$predict(trees)

## Quantile regression
svm <- SVMTrainer$new(type="qt")
svm$fit(trees,"Height")
p <- svm$predict(trees)
# }

Run the code above in your browser using DataLab