Description Format Usage Arguments Details Fields Methods Examples
BaselearnerCustom
creates a custom base-learner factory by
setting custom R
functions. This factory object can be registered
within a base-learner list and then used for training.
S4
object.
1 2 | BaselearnerCustom$new(data_source, data_target, instantiateData, train,
predict, extractParameter)
|
data_source
[Data
Object]Data object which contains the source data.
data_target
[Data
Object]Data object which gets the transformed source data.
instantiateData
[function
]R
function to transform the source data. For details see the
Details
.
train
[function
]R
function to train the base-learner on the target data. For
details see the Details
.
predict
[function
]R
function to predict on the object returned by train
.
For details see the Details
.
extractParameter
[function
]R
function to extract the parameter of the object returned by
train
. For details see the Details
.
The function must have the following structure:
instantiateData(X) { ... return (X.trafo) }
With a matrix argument
X
and a matrix as return object.
train(y, X) { ... return (SEXP) }
With a vector argument y
and a matrix argument X
. The target data is used in X
while
y
contains the response. The function can return any R
object which is stored within a SEXP
.
predict(model, newdata) { ... return (prediction) }
The returned
object of the train
function is passed to the model
argument while newdata
contains a new matrix used for predicting.
extractParameter() { ... return (parameters) }
Again, model
contains the object returned by train
. The returned object must be
a matrix containing the estimated parameter. If no parameter should be
estimated one can return NA
.
For an example see the Examples
.
This class is a wrapper around the pure C++
implementation. To see
the functionality of the C++
class visit
https://schalkdaniel.github.io/compboost/cpp_man/html/classblearnerfactory_1_1_custom_blearner_factory.html.
This class doesn't contain public fields.
getData()
Get the data matrix of the target data which is used for modeling.
transformData(X)
Transform a data matrix as defined within the factory. The argument has to be a matrix with one column.
summarizeFactory()
Summarize the base-learner factory object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # Sample data:
data.mat = cbind(1, 1:10)
y = 2 + 3 * 1:10
# Create new data object:
data.source = InMemoryData$new(data.mat, "my.data.name")
data.target = InMemoryData$new()
instantiateDataFun = function (X) {
return(X)
}
# Ordinary least squares estimator:
trainFun = function (y, X) {
return(solve(t(X) %*% X) %*% t(X) %*% y)
}
predictFun = function (model, newdata) {
return(as.matrix(newdata %*% model))
}
extractParameter = function (model) {
return(as.matrix(model))
}
# Create new custom linear base-learner factory:
custom.lin.factory = BaselearnerCustom$new(data.source, data.target,
instantiateDataFun, trainFun, predictFun, extractParameter)
# Get the transformed data:
custom.lin.factory$getData()
# Summarize factory:
custom.lin.factory$summarizeFactory()
# Transform data manually:
custom.lin.factory$transformData(data.mat)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.