如何创建 RLearner_regr_QRNN.R?
How can I create RLearner_regr_QRNN.R?
原题
我想为分位数回归神经网络创建一个新的学习器。它不在已与 "mlr" 集成的学习方法列表中。它的格式必须是这样的 "RLearner_regr_QRNN.R"
答案被接受后添加
我想将 "quantile regression neural network" 定义为一种新型学习器,它具有特殊属性并且不适合现有方案之一。我的代码如下。代码正在运行,但是当我将它用作我的数据的学习器时,它给出了一个错误,即 'qrnn' 不是从 'namespace:qrnn' 导出的对象。非常感谢您,期待您的回音。
makeRLearner.regr.qrnn = function() {
makeRLearnerRegr(
cl = "regr.qrnn",
package = "qrnn",
par.set = makeParamSet(
makeIntegerLearnerParam(id = "n.hidden", default = 2L, lower = 1L),
makeUntypedLearnerParam(id = "n.hidden2", default = NULL),
makeUntypedLearnerParam(id = "w", default = NULL),
makeNumericVectorLearnerParam(id = "tau", default = c(0.1, 0.5, 0.9)),
makeIntegerLearnerParam(id = "iter.max", default = 5000L),
makeIntegerLearnerParam(id = "n.trials", default = 5L),
makeNumericLearnerParam(id = "lower", default = 0),
makeNumericVectorLearnerParam(id = "init.range", default = c(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5)),
makeUntypedLearnerParam(id = "monotone", default = NULL),
makeNumericVectorLearnerParam(id = "eps.seq", default =c(2^(-8),2^(-12),2^(-16),2^(-20),2^(-24),2^(-28),2^(-32))),
makeDiscreteLearnerParam(id = "Th", values =c("sigmoid", "elu", "softplus"),default = "sigmoid"),
makeDiscreteLearnerParam(id = "Th.prime", values=c("sigmoid.prime", "elu.prime","softplus.prime", default = "sigmoid.prime")),
makeNumericLearnerParam(id = "penalty", default = 0),
makeIntegerLearnerParam(id = "n.errors.max", default = 10),
makeLogicalLearnerParam(id = "trace", default = TRUE),
makeDiscreteLearnerParam(id = "method", values =c("nlm","adam"), default = "nlm")
),
par.vals = list(n.hidden=5L, penalty=0),
properties = c("numerics", "factors", "ordered", "oobpreds", "featimp", "se", "weights"),
name = "QRNN",
short.name = "qrnn",
callees = "qrnn"
)
}
#' @export
trainLearner.regr.qrnn = function(.learner, .task, .subset, .weights = NULL, ...) {
if (is.null(.weights)) {
f = getTaskFormula(.task)
qrnn::qrnn(f, data = getTaskData(.task, .subset), linout = TRUE, ...)
} else {
f = getTaskFormula(.task)
qrnn::qrnn(f, data = getTaskData(.task, .subset), linout = TRUE, weights = .weights, ...)
}
}
#' @export
predictLearner.regr.qrnn = function(.learner, .model, .newdata, ...) {
predict(.model$learner.model, newdata = .newdata, ...)[, 1L]
}
您可以在 our website 上找到有关如何创建自定义学习器的说明。
此外,您可能需要考虑为新的 mlr3 包创建该学习器。指令是 here.
原题
我想为分位数回归神经网络创建一个新的学习器。它不在已与 "mlr" 集成的学习方法列表中。它的格式必须是这样的 "RLearner_regr_QRNN.R"
答案被接受后添加
我想将 "quantile regression neural network" 定义为一种新型学习器,它具有特殊属性并且不适合现有方案之一。我的代码如下。代码正在运行,但是当我将它用作我的数据的学习器时,它给出了一个错误,即 'qrnn' 不是从 'namespace:qrnn' 导出的对象。非常感谢您,期待您的回音。
makeRLearner.regr.qrnn = function() {
makeRLearnerRegr(
cl = "regr.qrnn",
package = "qrnn",
par.set = makeParamSet(
makeIntegerLearnerParam(id = "n.hidden", default = 2L, lower = 1L),
makeUntypedLearnerParam(id = "n.hidden2", default = NULL),
makeUntypedLearnerParam(id = "w", default = NULL),
makeNumericVectorLearnerParam(id = "tau", default = c(0.1, 0.5, 0.9)),
makeIntegerLearnerParam(id = "iter.max", default = 5000L),
makeIntegerLearnerParam(id = "n.trials", default = 5L),
makeNumericLearnerParam(id = "lower", default = 0),
makeNumericVectorLearnerParam(id = "init.range", default = c(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5)),
makeUntypedLearnerParam(id = "monotone", default = NULL),
makeNumericVectorLearnerParam(id = "eps.seq", default =c(2^(-8),2^(-12),2^(-16),2^(-20),2^(-24),2^(-28),2^(-32))),
makeDiscreteLearnerParam(id = "Th", values =c("sigmoid", "elu", "softplus"),default = "sigmoid"),
makeDiscreteLearnerParam(id = "Th.prime", values=c("sigmoid.prime", "elu.prime","softplus.prime", default = "sigmoid.prime")),
makeNumericLearnerParam(id = "penalty", default = 0),
makeIntegerLearnerParam(id = "n.errors.max", default = 10),
makeLogicalLearnerParam(id = "trace", default = TRUE),
makeDiscreteLearnerParam(id = "method", values =c("nlm","adam"), default = "nlm")
),
par.vals = list(n.hidden=5L, penalty=0),
properties = c("numerics", "factors", "ordered", "oobpreds", "featimp", "se", "weights"),
name = "QRNN",
short.name = "qrnn",
callees = "qrnn"
)
}
#' @export
trainLearner.regr.qrnn = function(.learner, .task, .subset, .weights = NULL, ...) {
if (is.null(.weights)) {
f = getTaskFormula(.task)
qrnn::qrnn(f, data = getTaskData(.task, .subset), linout = TRUE, ...)
} else {
f = getTaskFormula(.task)
qrnn::qrnn(f, data = getTaskData(.task, .subset), linout = TRUE, weights = .weights, ...)
}
}
#' @export
predictLearner.regr.qrnn = function(.learner, .model, .newdata, ...) {
predict(.model$learner.model, newdata = .newdata, ...)[, 1L]
}
您可以在 our website 上找到有关如何创建自定义学习器的说明。
此外,您可能需要考虑为新的 mlr3 包创建该学习器。指令是 here.