set.seed(8)
n_instances <- 10
n_samples <- 20
y <- rep(c(1, -1), each = n_samples * n_instances / 2)
instances <- as.character(rep(1:n_instances, each = n_samples))
x <- data.frame(x1 = rnorm(length(y), mean = 1*(y==1)),
x2 = rnorm(length(y), mean = 2*(y==1)),
x3 = rnorm(length(y), mean = 3*(y==1)))
df <- data.frame(instance_name = instances, y = y, x)
mdl <- smm(x, y, instances)
mdl2 <- smm(y ~ ., data = df)
# instance level predictions
suppressWarnings(library(dplyr))
df %>%
dplyr::bind_cols(predict(mdl, type = "raw", new_data = x, new_instances = instances)) %>%
dplyr::bind_cols(predict(mdl, type = "class", new_data = x, new_instances = instances)) %>%
dplyr::distinct(instance_name, y, .pred, .pred_class)
Run the code above in your browser using DataLab