I Train the model in R store it in a binary format and the load in Java.
I was currently training a model in R 3.2.2 and Xgboost 0.4-2 and Predict using Xgboost JVM 0.72.
Both Predict functions in R and Java give me the same results for my input data.
BaseLine
8.847367984882893E-6
0.09427586244760379
4.262344683277366E-4
4.970554458048691E-4
0.004658706118213614
I updated R to 3.5.1 and Xgboost to 0.71.1 and 0.71.2 (Tried both), and Predicted using Xgboost JVM 0.72/0.81(Tried Both)
The R predict function gave this
1.37787336598784e-05
9.53892665644611e-02
2.01653583650557e-04
3.29090567502518e-04
6.10666029073281e-03
The Java Predictions gave this
0.29515123439824215
0.9995756389884775
0.9507827625419463
0.9846390802292272
0.9981499148687549
Is there some inconsistency in the R and Java prediction functions or am I missing something?
Training Environment
readr_1.1.0.tar.gz &&
jsonlite_1.4.tar.gz &&
xgboost_0.71.2.tar.gz &&
chron_2.3-47.tar.gz &&
data.table_1.10.4-3.tar.gz &&
magrittr_1.5.tar.gz &&
stringr_1.0.0.tar.gz &&
stringi_0.5-5.tar.gz &&
bindrcpp_0.2.tar.gz &&
tibble_1.3.1.tar.gz &&
BH_1.62.0-1.tar.gz &&
R6_2.2.0.tar.gz &&
hms_0.3.tar.gz &&
assertthat_0.2.0.tar.gz &&
rlang_0.1.4.tar.gz &&
Rcpp_0.12.17.tar.gz && \
R Predict
Sigmoid <- function(x) {
return (exp(x) / (exp(x) + 1))
}
raw.score = predict(model,as.matrix(x))
raw.score = Sigmoid(raw.score)
Java Predict
private double Sigmoid(double score)
{
return Math.exp(score) / (Math.exp(score) + 1);
}
Booster booster = XGBoost.loadModel(“model.bin”);
DMatrix dMatrix = new DMatrix(fvec, 1, fvec.length);
float[][] prediction = booster.predict(dMatrix);
return Sigmoid(prediction[0][0]);
There is no code change in both of training and prediction. Is there something I am missing?
I also tried predicting models trained on R 3.2.2 Xgb 0.4-2 with R 3.5.1 Xgb 0.71.2 and go following results:
0.282819604863266
0.997937636304315
0.970238370838886
0.979681025161069
0.997780969263874
which is similar to Predictions trained on R3.5.1 Xgb 0.71.2 and predicting in XGB Jvm 0.72.