tune_wsvm {WeightSVM}R Documentation

Parameter Tuning of Functions Using Grid Search

Description

This generic function tunes hyperparameters of statistical methods using a grid search over supplied parameter ranges.

Usage

tune_wsvm(train.x, train.y = NULL, weight, use_zero_weight = FALSE,
     pre.check = TRUE, data = list(), validation.x = NULL,
     validation.y = NULL, validation.weight = NULL,
     weigthed.error = TRUE, ranges = NULL, predict.func = predict,
     tunecontrol = tune.control(), ...)
best.tune_wsvm(...)

Arguments

train.x

either a formula or a 'design matrix' of predictors.

train.y

the response variable if train.x is a predictor matrix. Ignored if train.x is a formula.

weight

the weight of each subject. It should be in the same length of train.y.

use_zero_weight

if FALSE, any subjects in the training data and the validation data (if exist) with zero (or negative) weights will be removed.

pre.check

if TRUE, we prefit the model with partitioned training data using the first set of parameters in range. If fails (i.e., too many zero weight subjects in the partitioned training data), we re-partition the data and re-try the model for up to 10 times. This is useful when use_zero_weight=TRUE and there many zero weights subjects in the data.

data

data, if a formula interface is used. Ignored, if predictor matrix and response are supplied directly.

validation.x

an optional validation set. Depending on whether a formula interface is used or not, the response can be included in validation.x or separately specified using validation.y. Only used for bootstrap and fixed validation set (see tune.control)

validation.y

if no formula interface is used, the response of the (optional) validation set. Only used for bootstrap and fixed validation set (see tune.control)

validation.weight

the weight of each subject in the validation set. Will be set to 1, if the user does not provide.

weigthed.error

if TRUE, the preformance measure will be weighted.

ranges

a named list of parameter vectors spanning the sampling space. See wsvm. The vectors will usually be created by seq.

predict.func

optional predict function, if the standard predict behavior is inadequate.

tunecontrol

object of class "tune.control", as created by the function tune.control(). In additon, tune.control$error.fun should be a function that takes three arguments: (true y, predicted y, weight). If omitted, tune.control() gives the defaults.

...

Further parameters passed to the training functions.

Details

As performance measure, the classification error is used for classification, and the mean squared error for regression. It is possible to specify only one parameter combination (i.e., vectors of length 1) to obtain an error estimation of the specified type (bootstrap, cross-classification, etc.) on the given data set.

Cross-validation randomizes the data set before building the splits which—once created—remain constant during the training process. The splits can be recovered through the train.ind component of the returned object.

Value

For tune_wsvm, an object of class tune_wsvm, including the components:

best.parameters

a 1 x k data frame, k number of parameters.

best.performance

best achieved performance.

performances

if requested, a data frame of all parameter combinations along with the corresponding performance results.

train.ind

list of index vectors used for splits into training and validation sets.

best.model

if requested, the model trained on the complete training data using the best parameter combination.

best.tune_wsvm() returns the best model detected by tune_wsvm.

Author(s)

David Meyer
Modified by Tianchen Xu tx2155@columbia.edu

See Also

tune.control, plot.tune_wsvm

Examples

data(iris)

obj <- tune_wsvm(Species~., weight = c(rep(0.8, 50),rep(1,100)),
            data = iris, ranges = list(gamma = 2^(-1:1), cost = 2^(2:4)),
            tunecontrol = tune.control(sampling = "fix"))


set.seed(11)
obj <- tune_wsvm(Species~., weight = c(rep(0, 52),rep(1,98)),
            data = iris, use_zero_weight = TRUE,
            ranges = list(gamma = 2^(-1:1), cost = 2^(2:4)),
            tunecontrol = tune.control(sampling = "bootstrap"))



summary(obj)
plot(obj, transform.x = log2, transform.y = log2)
plot(obj, type = "perspective", theta = 120, phi = 45)

best.tune_wsvm(Species~.,weight = c(rep(0.08, 50),rep(1,100)),
            data = iris, ranges = list(gamma = 2^(-1:1), cost = 2^(2:4)),
            tunecontrol = tune.control(sampling = "fix"))

[Package WeightSVM version 1.7-13 Index]