Description Usage Arguments Value How to create a new train base method Examples
Base classifiers are used to build models to solve the the transformation problems. To create a new base classifier, two steps are necessary:
Create a train method
Create a prediction method
This section is about how to create the first step: a train method.
To create a new predict model see mlpredict
documentation.
1 |
object |
A
Others values may be specified by the multi-label method. |
... |
Others arguments passed to the base method. |
A model object. The class of this model can be of any type, however, this object will be passed to the respective mlpredict method.
First, is necessary to define a name of your classifier, because this name
determines the method name. The base method name must start with
mltrain.base
followed by the designed name, e.g. a 'FOO'
classify must be defined as mltrain.baseFOO
(we suggest always use
upper case names).
Next, your method must receive at least two parameters (object, ...
).
Use object$data[, object$labelindex]
or
object$data[, object$labelname]
to access the labels values and use
object$data[, -object$labelindex]
to access the predictive attributes.
If you need to know which are the multi-label dataset and method, use
object$mldataset
and object$mlmethod
, respectively.
Finally, your method should return a model that will be used by the mlpredict method. Remember, that your method may be used to build binary and multi-class models.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Create a empty model of type FOO
mltrain.baseFOO <- function (object, ...) {
mymodel <- list(
classes = as.character(unique(object$data[, object$labelindex]))
)
class(mymodel) <- 'fooModel'
mymodel
}
# Using this base method with Binary Relevance
brmodel <- br(toyml, 'FOO')
# Create a SVM method using the e1071 package
library(e1071)
mltrain.baseSVM <- function (object, ...) {
traindata <- object$data[, -object$labelindex]
labeldata <- object$data[, object$labelindex]
model <- svm(traindata, labeldata, probability = TRUE, ...)
model
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.