For showing model fitting in SSLR
, we will use Wine dataset with 20% labeled data:
library(SSLR)
library(tidymodels)
library(caret)
data(wine)
set.seed(1)
#Train and test data
<- createDataPartition(wine$Wine, p = .7, list = FALSE)
train.index <- wine[ train.index,]
train <- wine[-train.index,]
test
<- which(colnames(wine) == "Wine")
cls
# 20 % LABELED
<- createDataPartition(wine$Wine, p = .2, list = FALSE)
labeled.index -labeled.index,cls] <- NA train[
In this package we have three functions to fit the different models:
We can use a formula with data (matrix or data.frame, with unlabeled data NAs in column to predict):
<- SSLRDecisionTree() %>% fit(Wine ~ ., data = train) m
We can use x data (matrix or data.frame) and y vector (factor or numeric, with unlabeled data NAs):
<- SSLRDecisionTree() %>% fit_xy(x = train[,-cls], y = train$Wine) m
We can use a x (matrix or data.frame) and y vector (factor or numeric, without NAs) and unalabeled data without y column (matrix or data.frame):
<- SSLRDecisionTree() %>% fit_x_u(x = train[labeled.index,-cls], y = train[labeled.index,cls],
m x_U = train[-labeled.index,-cls])