Skip to content

Commit

Permalink
Add bestSpecificLearner
Browse files Browse the repository at this point in the history
  • Loading branch information
fouodo committed Sep 26, 2024
1 parent ee1d439 commit 258d8fd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Depends: R (>= 3.6.0)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Collate:
'BestSpecificLearner.R'
'Data.R'
'HashTable.R'
'Lrner.R'
Expand All @@ -46,4 +47,5 @@ Collate:
'VarSel.R'
'entities.R'
'weightedMeanLearner.R'
'predict.bestSpecificLearner.R'
'predict.weightedMeanLearner.R'
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(predict,bestSpecificLearner)
S3method(predict,weightedMeanLearner)
export(Data)
export(HashTable)
Expand All @@ -22,6 +23,7 @@ export(TrainLayer)
export(TrainMetaLayer)
export(Training)
export(VarSel)
export(bestSpecificLearner)
export(weightedMeanLearner)
importFrom(R6,R6Class)
importFrom(digest,digest)
Expand Down
36 changes: 36 additions & 0 deletions tests/testthat/test-bestSpecificLearner.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
test_that("bestSpecificLearner works", {
expect_no_error({
set.seed(20240624L)
x = data.frame(x1 = runif(n = 50L, min = 0, max = 1))
y = sample(x = 0L:1L, size = 50L, replace = TRUE)
my_model = bestSpecificLearner(x = x, y = y)
x_new <- data.frame(x1 = rnorm(10))
my_predictions <- predict(object = my_model, data = x_new)
})
expect_error({
set.seed(20240624L)
x = data.frame(x1 = runif(n = 50L, min = 0, max = 1))
y = sample(x = 0L:1L, size = 50L, replace = TRUE)
my_model = bestSpecificLearner(x = x, y = y)
x_new <- data.frame(x2 = rnorm(10))
my_predictions <- predict(object = my_model, data = x_new)
})
expect_error({
set.seed(20240624L)
x = data.frame(x1 = runif(n = 50L, min = 0, max = 1))
y = sample(x = 0L:2L, size = 50L, replace = TRUE)
my_model = bestSpecificLearner(x = x, y = y)
})
expect_no_error({
set.seed(20240624L)
x = data.frame(x1 = runif(n = 50L, min = 0, max = 1))
y = factor(sample(x = c("control", "case"), size = 50L, replace = TRUE))
my_model = bestSpecificLearner(x = x, y = y)
})
expect_no_error({
set.seed(20240624L)
x = data.frame(x1 = runif(n = 50L, min = 0, max = 1))
y = sample(x = c("0", "1"), size = 50L, replace = TRUE)
my_model = bestSpecificLearner(x = x, y = factor(y))
})
})

0 comments on commit 258d8fd

Please sign in to comment.