| mlSvm {mlearning} | R Documentation |
Supervised classification and regression using support vector machine
Description
Unified (formula-based) interface version of the support vector machine
algorithm provided by e1071::svm().
Usage
mlSvm(train, ...)
ml_svm(train, ...)
## S3 method for class 'formula'
mlSvm(
formula,
data,
scale = TRUE,
type = NULL,
kernel = "radial",
classwt = NULL,
...,
subset,
na.action
)
## Default S3 method:
mlSvm(
train,
response,
scale = TRUE,
type = NULL,
kernel = "radial",
classwt = NULL,
...
)
## S3 method for class 'mlSvm'
predict(
object,
newdata,
type = c("class", "membership", "both"),
method = c("direct", "cv"),
na.action = na.exclude,
...
)
Arguments
train |
a matrix or data frame with predictors. |
... |
further arguments passed to the classification or regression
method. See |
formula |
a formula with left term being the factor variable to predict
(for supervised classification), a vector of numbers (for regression) or
nothing (for unsupervised classification) and the right term with the list
of independent, predictive variables, separated with a plus sign. If the
data frame provided contains only the dependent and independent variables,
one can use the |
data |
a data.frame to use as a training set. |
scale |
are the variables scaled (so that mean = 0 and standard
deviation = 1)? |
type |
For |
kernel |
the kernel used by svm, see |
classwt |
priors of the classes. Need not add up to one. |
subset |
index vector with the cases to define the training set in use (this argument must be named, if provided). |
na.action |
function to specify the action to be taken if |
response |
a vector of factor (classification) or numeric (regression). |
object |
an mlSvm object |
newdata |
a new dataset with same conformation as the training set (same variables, except may by the class for classification or dependent variable for regression). Usually a test set, or a new dataset to be predicted. |
method |
|
Value
ml_svm()/mlSvm() creates an mlSvm, mlearning object
containing the classifier and a lot of additional metadata used by the
functions and methods you can apply to it like predict() or
cvpredict(). In case you want to program new functions or extract
specific components, inspect the "unclassed" object using unclass().
See Also
mlearning(), cvpredict(), confusion(), also e1071::svm()
that actually does the calculation.
Examples
# Prepare data: split into training set (2/3) and test set (1/3)
data("iris", package = "datasets")
train <- c(1:34, 51:83, 101:133)
iris_train <- iris[train, ]
iris_test <- iris[-train, ]
# One case with missing data in train set, and another case in test set
iris_train[1, 1] <- NA
iris_test[25, 2] <- NA
iris_svm <- ml_svm(data = iris_train, Species ~ .)
summary(iris_svm)
predict(iris_svm) # Default type is class
predict(iris_svm, type = "membership")
predict(iris_svm, type = "both")
# Self-consistency, do not use for assessing classifier performances!
confusion(iris_svm)
# Use an independent test set instead
confusion(predict(iris_svm, newdata = iris_test), iris_test$Species)
# Another dataset
data("HouseVotes84", package = "mlbench")
house_svm <- ml_svm(data = HouseVotes84, Class ~ ., na.action = na.omit)
summary(house_svm)
# Cross-validated confusion matrix
confusion(cvpredict(house_svm), na.omit(HouseVotes84)$Class)
# Regression using support vector machine
data(airquality, package = "datasets")
ozone_svm <- ml_svm(data = airquality, Ozone ~ ., na.action = na.omit)
summary(ozone_svm)
plot(na.omit(airquality)$Ozone, predict(ozone_svm))
abline(a = 0, b = 1)