| SVC {less} | R Documentation |
Support Vector Classification
Description
Wrapper R6 Class of e1071::svm function that can be used for LESSRegressor and LESSClassifier
Value
R6 Class of SVC
Super classes
less::BaseEstimator -> less::SklearnEstimator -> SVC
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of R6 Class of SVC
Usage
SVC$new( scale = TRUE, kernel = "radial", degree = 3, gamma = NULL, coef0 = 0, cost = 1, cache_size = 40, tolerance = 0.001, epsilon = 0.1, shrinking = TRUE, cross = 0, probability = FALSE, fitted = TRUE )
Arguments
scaleA logical vector indicating the variables to be scaled. If scale is of length 1, the value is recycled as many times as needed. Per default, data are scaled internally (both x and y variables) to zero mean and unit variance. The center and scale values are returned and used for later predictions (default: TRUE)
kernelThe kernel used in training and predicting. Possible values are: "linear", "polynomial", "radial", "sigmoid" (default is "radial")
degreeParameter needed for kernel of type polynomial (default: 3)
gammaParameter needed for all kernels except linear (default: 1/(data dimension))
coef0Parameter needed for kernels of type polynomial and sigmoid (default: 0)
costCost of constraints violation (default: 1)—it is the ‘C’-constant of the regularization term in the Lagrange formulation (default: 1)
cache_sizeCache memory in MB (default: 40)
toleranceTolerance of termination criterion (default: 0.001)
epsilonEpsilon in the insensitive-loss function (default: 0.1)
shrinkingOption whether to use the shrinking-heuristics (default: TRUE)
crossIf a integer value k>0 is specified, a k-fold cross validation on the training data is performed to assess the quality of the model: the accuracy rate for classification and the Mean Squared Error for regression (default: 0)
probabilityLogical indicating whether the model should allow for probability predictions (default: FALSE)
fittedLogical indicating whether the fitted values should be computed and included in the model or not (default: TRUE)
Examples
svc <- SVC$new() svc <- SVC$new(kernel = "polynomial")
Method fit()
Fit the SVM model from the training set (X, y).
Usage
SVC$fit(X, y)
Arguments
X2D matrix or dataframe that includes predictors
y1D vector or (n,1) dimensional matrix/dataframe that includes labels
Returns
Fitted R6 Class of SVC
Examples
data(iris) split_list <- train_test_split(iris, test_size = 0.3) X_train <- split_list[[1]] X_test <- split_list[[2]] y_train <- split_list[[3]] y_test <- split_list[[4]] svc <- SVC$new() svc$fit(X_train, y_train)
Method predict()
Predict regression value for X0.
Usage
SVC$predict(X0)
Arguments
X02D matrix or dataframe that includes predictors
Returns
Factor of the predict classes.
Examples
svc <- SVC$new() svc$fit(X_train, y_train) preds <- svc$predict(X_test) svc <- SVC$new() preds <- svc$fit(X_train, y_train)$predict(X_test) preds <- SVC$new()$fit(X_train, y_train)$predict(X_test) print(caret::confusionMatrix(data=preds, reference = factor(y_test)))
Method get_estimator_type()
Auxiliary function returning the estimator type e.g 'regressor', 'classifier'
Usage
SVC$get_estimator_type()
Examples
svc$get_estimator_type()
Method clone()
The objects of this class are cloneable with this method.
Usage
SVC$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Examples
## ------------------------------------------------
## Method `SVC$new`
## ------------------------------------------------
svc <- SVC$new()
svc <- SVC$new(kernel = "polynomial")
## ------------------------------------------------
## Method `SVC$fit`
## ------------------------------------------------
data(iris)
split_list <- train_test_split(iris, test_size = 0.3)
X_train <- split_list[[1]]
X_test <- split_list[[2]]
y_train <- split_list[[3]]
y_test <- split_list[[4]]
svc <- SVC$new()
svc$fit(X_train, y_train)
## ------------------------------------------------
## Method `SVC$predict`
## ------------------------------------------------
svc <- SVC$new()
svc$fit(X_train, y_train)
preds <- svc$predict(X_test)
svc <- SVC$new()
preds <- svc$fit(X_train, y_train)$predict(X_test)
preds <- SVC$new()$fit(X_train, y_train)$predict(X_test)
print(caret::confusionMatrix(data=preds, reference = factor(y_test)))
## ------------------------------------------------
## Method `SVC$get_estimator_type`
## ------------------------------------------------
svc$get_estimator_type()