n <- 1e3
x1 <- rnorm(n, sd = 2)
x2 <- rnorm(n)
lp <- x2*x1 + cos(x1)
yb <- rbinom(n, 1, lava::expit(lp))
y <- lp + rnorm(n, sd = 0.5**.5)
d0 <- data.frame(y, yb, x1, x2)
# regression
lr <- learner_xgboost(y ~ x1 + x2, nrounds = 5)
lr$estimate(d0)
lr$predict(head(d0))
# binary classification
lr <- learner_xgboost(yb ~ x1 + x2, nrounds = 5,
objective = "binary:logistic"
)
lr$estimate(d0)
lr$predict(head(d0))
# multi-class classification
d0 <- iris
d0$y <- as.numeric(d0$Species)- 1
lr <- learner_xgboost(y ~ ., objective = "multi:softprob", num_class = 3)
lr$estimate(d0)
lr$predict(head(d0))
Run the code above in your browser using DataLab