Skip to content

Instantly share code, notes, and snippets.

library(xgboost)
set.seed(1234)
N = 1000
x1 <- runif(N)
x <- ifelse(x1 <= 0.2, as.numeric(NA), x1)
y <- as.numeric(x1 >= 0.9)
bst <- xgboost(data = matrix(x, ncol=1), label = y,
objective = "binary:logistic", eval_metric = "logloss",
@jtilly
jtilly / check-lgb-multiclass.R
Last active May 12, 2018 08:16
dim(preds) vs. dim(predict(...)): what the hell is LightGBM doing?
library(lightgbm)
library(tidyverse)
rm(list = ls())
# We load the default iris dataset shipped with R
data(iris)
iris = as_data_frame(iris) %>%
mutate(Species = as.numeric(factor(Species)) - 1) %>%
@jtilly
jtilly / xgb-missings.md
Last active October 11, 2018 13:42
Treatment of missing values with and without sparse matrices
library(xgboost)
library(dplyr)

params = list(min_child_weight = 0.00001, lambda = 0 )
nrounds = 1

# sparse ---