-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
Copy pathRLearner_classif_rknn.R
33 lines (31 loc) · 1.13 KB
/
RLearner_classif_rknn.R
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
#' @export
makeRLearner.classif.rknn = function(){
makeRLearnerClassif(
cl = "classif.rknn",
package = "rknn",
par.set = makeParamSet(
makeIntegerLearnerParam(id = "k", default = 1L, lower = 1L, upper = 98L),
makeIntegerLearnerParam(id = "r", default = 500L, lower = 1L),
makeIntegerLearnerParam(id = "mtry", lower = 1L),
makeIntegerLearnerParam(id = "seed", lower = 1L),
makeUntypedLearnerParam(id = "cluster", default = NULL)
),
# rknn can't handle unordered factors or return probs
properties = c("twoclass", "multiclass", "numerics", "ordered"),
name = "Random k-Nearest-Neighbors",
short.name = "rknn",
note = "k restricted to < 99 as the code allocates arrays of static size",
callees = "rknn"
)
}
#' @export
trainLearner.classif.rknn = function(.learner, .task, .subset, .weights = NULL, ...){
z = getTaskData(.task, .subset, target.extra = TRUE)
c(list(data = z$data, y = z$target ), list(...))
}
#' @export
predictLearner.classif.rknn = function(.learner, .model, .newdata, ...){
args = .model$learner.model
args$newdata = .newdata
do.call(rknn::rknn, args)$pred
}