Skip to content

Instantly share code, notes, and snippets.

@actsasflinn
Created January 4, 2017 12:28
Show Gist options
  • Save actsasflinn/c0c1a04a4d84f1f039d57d5eb3f0571b to your computer and use it in GitHub Desktop.
Save actsasflinn/c0c1a04a4d84f1f039d57d5eb3f0571b to your computer and use it in GitHub Desktop.
library(jug)
library(xgboost)
library(Matrix)
setwd("~/Projects/xgboost_test")
model <- xgb.load("xgboost1.save")
jug() %>%
get("/model/(?<age>.*)/(?<workclass>.*)/(?<education>.*)/(?<marital_status>.*)/(?<occupation>.*)/(?<relationship>.*)/(?<gender>.*)", function(req, res, err){
df <- data.frame(
age = as.numeric(req$params$age),
workclass = req$params$workclass,
education = req$params$education,
marital_status = req$params$marital_status,
occupation = req$params$occupation,
relationship = req$params$relationship,
gender = req$params$gender
)
df$score <- predict(model, data.matrix(df))
df$prediction <- df$score>0.5
cat(str(df))
res$json(df)
}) %>%
simple_error_handler_json() %>%
serve_it()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment