-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandard_supervised.R
43 lines (26 loc) · 1.1 KB
/
standard_supervised.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
34
35
36
37
38
39
40
41
library(dplyr)
library(checkmate,asserthat)
standard_supervised <- function(labeled_data,
unlabeled_data,
test_data,
target,
glm_formula) {
# some input checking
assert_data_frame(labeled_data)
assert_data_frame(unlabeled_data)
assert_data_frame(test_data)
assert_formula(glm_formula)
assert_character(target)
logistic_model <- glm(formula = formula,
data = labeled_data,
family = "binomial")
# predict on unlabeled
predicted_target <- predict(logistic_model, newdata = unlabeled_data, type = "response")
new_labeled_obs <- unlabeled_data
new_labeled_obs[c(target)] <- ifelse(predicted_target > 0.5, 1,0)
predicted_label <- new_labeled_obs[c(target)] %>% unlist()
number <- new_labeled_obs$nr %>% unlist()
results <- cbind(number, predicted_label)
# return transductive results (labels) and final model
list(results, logistic_model)
}