| mlLvq | R Documentation |
Unified (formula-based) interface version of the learning vector quantization
algorithms provided by class::olvq1(), class::lvq1(), class::lvq2(),
and class::lvq3().
mlLvq(train, ...)
ml_lvq(train, ...)
## S3 method for class 'formula'
mlLvq(
formula,
data,
k.nn = 5,
size,
prior,
algorithm = "olvq1",
...,
subset,
na.action
)
## Default S3 method:
mlLvq(train, response, k.nn = 5, size, prior, algorithm = "olvq1", ...)
## S3 method for class 'mlLvq'
summary(object, ...)
## S3 method for class 'summary.mlLvq'
print(x, ...)
## S3 method for class 'mlLvq'
predict(
object,
newdata,
type = "class",
method = c("direct", "cv"),
na.action = na.exclude,
...
)
train |
a matrix or data frame with predictors. |
... |
further arguments passed to the classification method or its
|
formula |
a formula with left term being the factor variable to predict
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. |
k.nn |
k used for k-NN number of neighbor considered. Default is 5. |
size |
the size of the codebook. Defaults to min(round(0.4 \* nc \* (nc - 1 + p/2),0), n) where nc is the number of classes. |
prior |
probabilities to represent classes in the codebook (default values are the proportions in the training set). |
algorithm |
|
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 [ml_lvq)]: R:ml_lvq) |
response |
a vector of factor of the classes. |
x, object |
an mlLvq 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. |
type |
the type of prediction to return. For this method, only |
method |
|
ml_lvq()/mlLvq() creates an mlLvq, 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().
mlearning(), cvpredict(), confusion(), also class::olvq1(),
class::lvq1(), class::lvq2(), and class::lvq3() that actually do the
classification.
# 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_lvq <- ml_lvq(data = iris_train, Species ~ .)
summary(iris_lvq)
predict(iris_lvq) # This object only returns classes
#' # Self-consistency, do not use for assessing classifier performances!
confusion(iris_lvq)
# Use an independent test set instead
confusion(predict(iris_lvq, newdata = iris_test), iris_test$Species)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.