6.20 Support Vector Machine
The ore.odmSVM
function builds an OML4R Support Vector Machine (SVM) model.
SVM is a powerful, state-of-the-art algorithm with strong theoretical foundations based on the Vapnik-Chervonenkis theory. SVM has strong regularization properties. Regularization refers to the generalization of the model to new data.
SVM models have similar functional form to neural networks and radial basis functions, both popular machine learning techniques.
SVM can be used to solve the following problems:
-
Classification: SVM classification is based on decision planes that define decision boundaries. A decision plane is one that separates between a set of objects having different class memberships. SVM finds the vectors (“support vectors") that define the separators that give the widest separation of classes.
SVM classification supports both binary and multiclass targets.
-
Regression: SVM uses an epsilon-insensitive loss function to solve regression problems.
SVM regression tries to find a continuous function such that the maximum number of data points lie within the epsilon-wide insensitivity tube. Predictions falling within epsilon distance of the true target value are not interpreted as errors.
-
Anomaly Detection: Anomaly detection identifies identify cases that are unusual within data that is seemingly homogeneous. Anomaly detection is an important tool for detecting fraud, network intrusion, and other rare events that may have great significance but are hard to find.
Anomaly detection is implemented as one-class SVM classification. An anomaly detection model predicts whether a data point is typical for a given distribution or not.
The ore.odmSVM
function builds each of these three different types of models. Some arguments apply to classification models only, some to regression models only, and some to anomaly detection models only.
For information on the ore.odmSVM
function arguments, call help(ore.odmSVM)
.
Settings for a Support Vector Machine Models
The following table lists settings that apply to Support Vector Machine models.
Table 6-22 Support Vector Machine Model Settings
Setting Name | Setting Value | Description |
---|---|---|
|
|
Regularization setting that balances the complexity of the model against model robustness to achieve good generalization on new data. SVM uses a data-driven approach to finding the complexity factor. Value of complexity factor for SVM algorithm (both Classification and Regression). Default value estimated from the data by the algorithm. |
|
|
Convergence tolerance for SVM algorithm. Default is |
|
|
Regularization setting for regression, similar to complexity factor. Epsilon specifies the allowable residuals, or noise, in the data. Value of epsilon factor for SVM regression. Default is |
|
|
Kernel for Support Vector Machine. Linear or Gaussian. The default value is |
|
|
The desired rate of outliers in the training data. Valid for One-Class SVM models only (Anomaly Detection). Default is |
SVMS_STD_DEV |
|
Controls the spread of the Gaussian kernel function. SVM uses a data-driven approach to find a standard deviation value that is on the same scale as distances between typical cases. Value of standard deviation for SVM algorithm. This is applicable only for Gaussian kernel. Default value estimated from the data by the algorithm. |
|
|
This setting sets an upper limit on the number of SVM iterations. The default is system determined because it depends on the SVM solver. |
SVMS_NUM_PIVOTS |
Range [ |
This setting sets an upper limit on the number of pivots used in the Incomplete Cholesky decomposition. It can be set only for non-linear kernels. The default value is |
|
|
This setting applies to SVM models with linear kernel. This setting sets the size of the batch for the SGD solver. An input of 0 triggers a data driven batch size estimate. The default is |
|
|
This setting controls the type of regularization that the SGD SVM solver uses. The setting can be used only for linear SVM models. The default is system determined because it depends on the potential model size. |
SVMS_SOLVER |
|
This setting allows the user to choose the SVM solver. The SGD solver cannot be selected if the kernel is non-linear. The default value is system determined. |
Example 6-23 Using the ore.odmSVM Function and Generating a Confusion Matrix
This example demonstrates the use of SVM classification. The example creates mtcars
in the database from the R mtcars
data set, builds a classification model, makes predictions, and finally generates a confusion matrix.
m <- mtcars m$gear <- as.factor(m$gear) m$cyl <- as.factor(m$cyl) m$vs <- as.factor(m$vs) m$ID <- 1:nrow(m) mtcars_of <- ore.push(m) svm.mod <- ore.odmSVM(gear ~ .-ID, mtcars_of, "classification") summary(svm.mod) svm.res <- predict (svm.mod, mtcars_of,"gear") with(svm.res, table(gear, PREDICTION)) # generate confusion matrix
Listing for This Example
R> m <- mtcars R> m$gear <- as.factor(m$gear) R> m$cyl <- as.factor(m$cyl) R> m$vs <- as.factor(m$vs) R> m$ID <- 1:nrow(m) R> mtcars_of <- ore.push(m) R> R> svm.mod <- ore.odmSVM(gear ~ .-ID, mtcars_of, "classification") R> summary(svm.mod) Call: ore.odmSVM(formula = gear ~ . - ID, data = mtcars_of, type = "classification") Settings: value prep.auto on active.learning al.enable complexity.factor 0.385498 conv.tolerance 1e-04 kernel.cache.size 50000000 kernel.function gaussian std.dev 1.072341 Coefficients: [1] No coefficients with gaussian kernel R> svm.res <- predict (svm.mod, mtcars_of,"gear") R> with(svm.res, table(gear, PREDICTION)) # generate confusion matrix PREDICTION gear 3 4 3 12 3 4 0 12 5 2 3
Example 6-24 Using the ore.odmSVM Function and Building a Regression Model
This example demonstrates SVM regression. The example creates a data frame, pushes it to a table, and then builds a regression model; note that ore.odmSVM
specifies a linear kernel.
x <- seq(0.1, 5, by = 0.02) y <- log(x) + rnorm(x, sd = 0.2) dat <-ore.push(data.frame(x=x, y=y)) # Build model with linear kernel svm.mod <- ore.odmSVM(y~x,dat,"regression", kernel.function="linear") summary(svm.mod) coef(svm.mod) svm.res <- predict(svm.mod,dat, supplemental.cols="x") head(svm.res,6)
Listing for This Example
R> x <- seq(0.1, 5, by = 0.02) R> y <- log(x) + rnorm(x, sd = 0.2) R> dat <-ore.push(data.frame(x=x, y=y)) R> R> # Build model with linear kernel R> svm.mod <- ore.odmSVM(y~x,dat,"regression", kernel.function="linear") R> summary(svm.mod) Call: ore.odmSVM(formula = y ~ x, data = dat, type = "regression", kernel.function = "linear") Settings: value prep.auto on active.learning al.enable complexity.factor 0.620553 conv.tolerance 1e-04 epsilon 0.098558 kernel.function linear Residuals: Min. 1st Qu. Median Mean 3rd Qu. Max. -0.79130 -0.28210 -0.05592 -0.01420 0.21460 1.58400 Coefficients: variable value estimate 1 x 0.6637951 2 (Intercept) 0.3802170 R> coef(svm.mod) variable value estimate 1 x 0.6637951 2 (Intercept) 0.3802170 R> svm.res <- predict(svm.mod,dat, supplemental.cols="x") R> head(svm.res,6) x PREDICTION 1 0.10 -0.7384312 2 0.12 -0.7271410 3 0.14 -0.7158507 4 0.16 -0.7045604 5 0.18 -0.6932702 6 0.20 -0.6819799
Example 6-25 Using the ore.odmSVM Function and Building an Anomaly Detection Model
This example demonstrates SVN anomaly detection. It uses mtcars_of
created in the classification example and builds an anomaly detection model.
svm.mod <- ore.odmSVM(~ .-ID, mtcars_of, "anomaly.detection") summary(svm.mod) svm.res <- predict (svm.mod, mtcars_of, "ID") head(svm.res) table(svm.res$PREDICTION)
Listing for This Example
R> svm.mod <- ore.odmSVM(~ .-ID, mtcars_of, "anomaly.detection") R> summary(svm.mod) Call: ore.odmSVM(formula = ~. - ID, data = mtcars_of, type = "anomaly.detection") Settings: value prep.auto on active.learning al.enable conv.tolerance 1e-04 kernel.cache.size 50000000 kernel.function gaussian outlier.rate .1 std.dev 0.719126 Coefficients: [1] No coefficients with gaussian kernel R> svm.res <- predict (svm.mod, mtcars_of, "ID") R> head(svm.res) '0' '1' ID PREDICTION Mazda RX4 0.4999405 0.5000595 1 1 Mazda RX4 Wag 0.4999794 0.5000206 2 1 Datsun 710 0.4999618 0.5000382 3 1 Hornet 4 Drive 0.4999819 0.5000181 4 1 Hornet Sportabout 0.4949872 0.5050128 5 1 Valiant 0.4999415 0.5000585 6 1 R> table(svm.res$PREDICTION) 0 1 5 27