Created
April 30, 2020 08:43
-
-
Save fclesio/fbecb5d6754ccb5606f511a879a02de9 to your computer and use it in GitHub Desktop.
API Prediction Function in H2O model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(LIMIT_BAL, SEX, EDUCATION, MARRIAGE, | |
AGE, PAY_0, PAY_2, PAY_3, PAY_4, PAY_5, | |
PAY_6, BILL_AMT1, BILL_AMT2, BILL_AMT3, | |
BILL_AMT4, BILL_AMT5, BILL_AMT6, PAY_AMT1, | |
PAY_AMT2, PAY_AMT3, PAY_AMT4, PAY_AMT5, PAY_AMT6) { | |
LIMIT_BAL <- as.numeric(LIMIT_BAL) | |
SEX <- as.numeric(SEX) | |
EDUCATION <- as.numeric(EDUCATION) | |
MARRIAGE <- as.numeric(MARRIAGE) | |
AGE <- as.numeric(AGE) | |
PAY_0 <- as.numeric(PAY_0) | |
PAY_2 <- as.numeric(PAY_2) | |
PAY_3 <- as.numeric(PAY_3) | |
PAY_4 <- as.numeric(PAY_4) | |
PAY_5 <- as.numeric(PAY_5) | |
PAY_6 <- as.numeric(PAY_6) | |
BILL_AMT1 <- as.numeric(BILL_AMT1) | |
BILL_AMT2 <- as.numeric(BILL_AMT2) | |
BILL_AMT3 <- as.numeric(BILL_AMT3) | |
BILL_AMT4 <- as.numeric(BILL_AMT4) | |
BILL_AMT5 <- as.numeric(BILL_AMT5) | |
BILL_AMT6 <- as.numeric(BILL_AMT6) | |
PAY_AMT1 <- as.numeric(PAY_AMT1) | |
PAY_AMT2 <- as.numeric(PAY_AMT2) | |
PAY_AMT3 <- as.numeric(PAY_AMT3) | |
PAY_AMT4 <- as.numeric(PAY_AMT4) | |
PAY_AMT5 <- as.numeric(PAY_AMT5) | |
PAY_AMT6 <- as.numeric(PAY_AMT6) | |
log_debug('Generate data.table with converted variables') | |
predict_objects <- data.frame( | |
LIMIT_BAL = c(LIMIT_BAL), | |
SEX = c(SEX), | |
EDUCATION = c(EDUCATION), | |
MARRIAGE = c(MARRIAGE), | |
AGE = c(AGE), | |
PAY_0 = c(PAY_0), | |
PAY_2 = c(PAY_2), | |
PAY_3 = c(PAY_3), | |
PAY_4 = c(PAY_4), | |
PAY_5 = c(PAY_5), | |
PAY_6 = c(PAY_6), | |
BILL_AMT1 = c(BILL_AMT1), | |
BILL_AMT2 = c(BILL_AMT2), | |
BILL_AMT3 = c(BILL_AMT3), | |
BILL_AMT4 = c(BILL_AMT4), | |
BILL_AMT5 = c(BILL_AMT5), | |
BILL_AMT6 = c(BILL_AMT6), | |
PAY_AMT1 = c(PAY_AMT1), | |
PAY_AMT2 = c(PAY_AMT2), | |
PAY_AMT3 = c(PAY_AMT3), | |
PAY_AMT4 = c(PAY_AMT4), | |
PAY_AMT5 = c(PAY_AMT5), | |
PAY_AMT6 = c(PAY_AMT6), | |
stringsAsFactors = FALSE | |
) | |
log_debug('Convert to H20.ai Object...') | |
predict_objects <- | |
as.h2o(predict_objects) | |
log_debug('Make prediction...') | |
prediction <- | |
h2o.predict(object = saved_model, | |
newdata = predict_objects) | |
prediction <- as.data.table(prediction) | |
log_debug('Default: {prediction}') | |
return(prediction) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment