In this example, we show in practice how to define a new base classifier using the function bClassif. We define a support vector machines as base classifier. For this, we define the functions train, predClass y predProb, needed as arguments of bClassif. We use the kernlab package to facilitate the definition of the SVM classifier. Next, we define the new base classifier denoted as bcSVM.

library(kernlab)

# Train function
train <- function(D, y){
  m <- ksvm(
    x = as.matrix(D),
    y = y,
    kernel = "matrix", # x is considered as kernel
    type = "C-svc",    # C classification
    C = 1,             # use a fix value for C
    prob.model = TRUE  # train to predict probabilities
  )
  m
}
# Classification function
predClass <- function(m, D){
  D <- as.matrix(D)
  D <- D[, SVindex(m)]
  predict(m, as.kernelMatrix(D), type="response")
}
# Probabilities prediction function
predProb <- function(m, D){
  D <- as.matrix(D)
  D <- D[, SVindex(m)]
  predict(m, as.kernelMatrix(D), type="probabilities")
}

bcSVM <- bClassif(train, predClass, predProb)

The new base classifier can be used to train any of the semi-supervised models available in ssc package. For example, we train the coBC model with 7 SVMs.

m.cobc <- coBC(x = xtrain, y = ytrain, dist = "Euclidean", bclassif = bcSVM, N = 7)
p.cobc <- predict(m.cobc, xitest)
statistics(p.cobc, yitest)