SVM_predict {DMTL}R Documentation

Predictive Modeling using Support Vector Machine

Description

This function trains a Support Vector Machine regressor using the training data provided and predict response for the test features. This implementation depends on the kernlab package.

Usage

SVM_predict(
  x_train,
  y_train,
  x_test,
  lims,
  kernel = "rbf",
  optimize = FALSE,
  C = 2,
  kpar = list(sigma = 0.1),
  eps = 0.01,
  seed = NULL,
  verbose = FALSE,
  parallel = FALSE
)

Arguments

x_train

Training features for designing the SVM regressor.

y_train

Training response for designing the SVM regressor.

x_test

Test features for which response values are to be predicted. If x_test is not given, the function will return the trained model.

lims

Vector providing the range of the response values for modeling. If missing, these values are estimated from the training response.

kernel

Kernel function for SVM implementation. The available options are linear, poly, rbf, and tanh. Defaults to rbf.

optimize

Flag for model tuning. If TRUE, performs a grid search for parameters. If FALSE, uses the parameters provided. Defaults to FALSE.

C

Cost of constraints violation. This is the constant "C" of the regularization term in the Lagrange formulation. Defaults to 2. Valid only when optimize = FALSE.

kpar

List of kernel parameters. This is a named list that contains the parameters to be used with the specified kernel. The valid parameters for the existing kernels are -

  • sigma for the radial basis (rbf) kernel. Note that this is the inverse kernel width.

  • degree, scale, offset for the polynomial kernel.

  • scale, offset for the hyperbolic tangent kernel.

Valid only when optimize = FALSE. Defaults to list(sigma = 0.1).

eps

The insensitive-loss function used for epsilon-SVR. Defaults to 0.01.

seed

Seed for random number generator (for reproducible outcomes). Defaults to NULL.

verbose

Flag for printing the tuning progress when optimize = TRUE. Defaults to FALSE.

parallel

Flag for allowing parallel processing when performing grid search i.e., optimimze = TRUE. Defaults to FALSE.

Value

If x_test is missing, the trained SVM regressor.

If x_test is provided, the predicted values using the model.

Note

The response values are filtered to be bound by range in lims.

Examples

set.seed(86420)
x <- matrix(rnorm(3000, 0.2, 1.2), ncol = 3);    colnames(x) <- paste0("x", 1:3)
y <- 0.3*x[, 1] + 0.1*x[, 2] - x[, 3] + rnorm(1000, 0, 0.05)

## Get the model only...
model <- SVM_predict(x_train = x[1:800, ], y_train = y[1:800], kernel = "rbf")

## Get predictive performance...
y_pred <- SVM_predict(x_train = x[1:800, ], y_train = y[1:800], x_test = x[801:1000, ])
y_test <- y[801:1000]
print(performance(y_test, y_pred, measures = "RSQ"))


[Package DMTL version 0.1.2 Index]