Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/PipeOp.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ PipeOp = R6::R6Class("PipeOp",
private$.id = id
private$.param_set = param_set
#FIXME: we really need a function in paradox now to get defaults
private$.param_vals = param_set$data$default
names(private$.param_vals) = param_set$ids
private$.param_vals = insert_named(private$.param_vals, param_vals)
if (!param_set$test(private$.param_vals)) {
stop("Parameters out of bounds")
private$.param_vals = param_set$defaults
if(!is.null(private$.param_vals)) {
if (!param_set$test(private$.param_vals)) {
stop("Parameters out of bounds")
}
}
},

Expand Down
10 changes: 6 additions & 4 deletions R/PipeOpDT.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ PipeOpDT = R6Class("PipeOpDT",
list(TaskClassif$new(id = task$id, backend = db, target = tn))
},

predict = function() {
assert_list(self$inputs, len = 1L, type = "Task")
predict = function(inputs) {
assert_list(inputs, len = 1L, type = "Task")
assert_function(self$predict_dt, args = "newdt")
task = self$inputs[[1L]]
task = inputs[[1L]]
fn = task$feature_names
d = task$data()

Expand All @@ -66,7 +66,9 @@ PipeOpDT = R6Class("PipeOpDT",
d[, (colnames(dt)) := dt]
d[, "..row_id" := seq_len(nrow(d))]

list(task$overwrite(d))
db = DataBackendDataTable$new(d, primary_key = task$backend$primary_key)
tn = task$target_names
list(TaskClassif$new(id = task$id, backend = db, target = tn))
}
)
)
5 changes: 3 additions & 2 deletions R/PipeOpLearner.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ PipeOpLearner = R6Class("PipeOpLearner", inherit = PipeOp,
# private$.result
},

predict2 = function() {
predict = function(inputs) {
assert_list(inputs, len = 1L, type = "Task")
predict(self$state)
task = inputs[[1L]]
list(self$state$learner$predict(task))
}
),

Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test_usecases.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ test_that("scale + pca", {
task = mlr_tasks$get("iris")
g = PipeOpScale$new() %>>% PipeOpPCA$new()
res1 = g$train(task)
assert_list(res1)
res2 = g$predict(task)

})

test_that("scale + pca + PipeOpLearner", {
task = mlr_tasks$get("iris")

g = PipeOpScale$new() %>>%
PipeOpPCA$new() %>>%
PipeOpLearner$new(mlr_learners$get("classif.rpart"))
res1 = g$train(task)
res2 = g$predict(task)
})