## ----------------------------------------------------------------------------- require(xgboost) require(jsonlite) require(float) options(digits=22) ## ----------------------------------------------------------------------------- dates <- c(20180130, 20180130, 20180130, 20180130, 20180130, 20180130, 20180131, 20180131, 20180131, 20180131, 20180131, 20180131, 20180131, 20180131, 20180131, 20180134, 20180134, 20180134) labels <- c(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) data <- data.frame(dates = dates, labels=labels) bst <- xgboost( data = as.matrix(data$dates), label = labels, nthread = 2, nrounds = 1, objective = "binary:logistic", missing = NA, max_depth = 1 ) ## ----------------------------------------------------------------------------- bst_json <- xgb.dump(bst, with_stats = FALSE, dump_format='json') bst_from_json <- fromJSON(bst_json, simplifyDataFrame = FALSE) node <- bst_from_json[[1]] cat(bst_json) ## ----------------------------------------------------------------------------- bst_preds_logodds <- predict(bst,as.matrix(data$dates), outputmargin = TRUE) # calculate the logodds values using the JSON representation bst_from_json_logodds <- ifelse(data$dates