library(ssc)
## Load Wine data set
data(wine)
cls <- which(colnames(wine) == "Wine")
x <- wine[, -cls] # instances without classes
y <- wine[, cls] # the classes
x <- scale(x) # scale the attributes
## Prepare data
set.seed(20)
# Use 50% of instances for training
tra.idx <- sample(x = length(y), size = ceiling(length(y) * 0.5))
xtrain <- x[tra.idx,] # training instances
ytrain <- y[tra.idx] # classes of training instances
# Use 70% of train instances as unlabeled set
tra.na.idx <- sample(x = length(tra.idx), size = ceiling(length(tra.idx) * 0.7))
ytrain[tra.na.idx] <- NA # remove class information of unlabeled instances
# Use the other 50% of instances for inductive testing
tst.idx <- setdiff(1:length(y), tra.idx)
xitest <- x[tst.idx,] # testing instances
yitest <- y[tst.idx] # classes of testing instances
Пакет ssc
содержит функцию-оболочку selfTraining
, которую можно использовать для обтекания любого контролируемого классификатора. Я пытаюсь обернуть это вокруг регрессионной модели логистики c:
mod <- selfTraining(x = xtrain, y = ytrain,
learner = function(x, y) stats::glm(y ~ x, family = "binomial"),
pred = "predict")
Однако, это дает мне ошибку Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
'data' must be a data.frame, not a matrix or an array
. Я также попытался
mod <- selfTraining(x = xtrain, y = ytrain,
learner = stats::glm,
learner.pars = list(family = "binomial"),
pred = "predict")
, что дает мне ошибку Error in formula.default(object, env = baseenv()) : invalid formula
.