mltrain: Build transformation models

Description Usage Arguments Value How to create a new train base method Examples

View source: R/base_learner.R

Description

Base classifiers are used to build models to solve the the transformation problems. To create a new base classifier, two steps are necessary:

  1. Create a train method

  2. 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.

Usage

1
mltrain(object, ...)

Arguments

object

A mltransformation object. This is used as a list and contains at least five values:

object$data

A data.frame with the train data, where the columns are the attributes and the rows are the examples.

object$labelname

The name of the class column.

object$labelindex

The column index of the class.

object$mldataset

The name of multi-label dataset.

object$mlmethod

The name of the multi-label method.

Others values may be specified by the multi-label method.

...

Others arguments passed to the base method.

Value

A model object. The class of this model can be of any type, however, this object will be passed to the respective mlpredict method.

How to create a new train base 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.

Examples

 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
}

rivolli/utiml documentation built on June 1, 2021, 11:48 p.m.