For showing regression SSLR
models, we will use Airquality dataset with 10% labeled data:
library(SSLR)
library(tidymodels)
::opts_chunk$set(
knitrdigits = 3,
collapse = TRUE,
comment = "#>"
)options(digits = 3)
library(SSLR)
library(tidymodels)
set.seed(1)
<- airquality
data #Delete column Solar.R (NAs values)
$Solar.R <- NULL
data#Train and test data
<- sample(nrow(data), round(0.7 * nrow(data)))
train.index <- data[ train.index,]
train <- data[-train.index,]
test
<- which(colnames(airquality) == "Ozone")
cls
#% LABELED
<- sample(nrow(train), round(0.1 * nrow(train)))
labeled.index -labeled.index,cls] <- NA train[
For example, we can train with Decision Tree:
<- SSLRDecisionTree(min_samples_split = round(length(labeled.index) * 0.25),
m w = 0.3) %>% fit(Ozone ~ ., data = train)
Now we can use metrics from yardstick
package:
predict(m,test)%>%
bind_cols(test) %>%
metrics(truth = "Ozone", estimate = .pred)
#> # A tibble: 3 x 3
#> .metric .estimator .estimate
#> <chr> <chr> <dbl>
#> 1 rmse standard 29.8
#> 2 rsq standard 0.525
#> 3 mae standard 18.6
We can train with Random Forest:
<- SSLRRandomForest(trees = 5, w = 0.3) %>% fit(Ozone ~ ., data = train) m
For example, we can train with coBC:
<- rand_forest( mode = "regression") %>%
m_r set_engine("ranger")
<- coBC(learner = m_r, max.iter = 1) %>% fit(Ozone ~ ., data = train) m
We can train with COREG:
#Load kknn
library(kknn)
<- COREG(max.iter = 1) %>% fit(Ozone ~ ., data = train) m_coreg