|
@@ -3,10 +3,9 @@ package com.tzld.piaoquan.ad.engine.commons.score.model;
|
|
|
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.CompressUtil;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.PropertiesUtil;
|
|
|
+import ml.dmlc.xgboost4j.scala.DMatrix;
|
|
|
import ml.dmlc.xgboost4j.scala.spark.XGBoostClassificationModel;
|
|
|
import org.apache.commons.lang.math.NumberUtils;
|
|
|
-import org.apache.spark.ml.linalg.Vector;
|
|
|
-import org.apache.spark.ml.linalg.Vectors;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -64,15 +63,18 @@ public class XGBoostModel extends Model {
|
|
|
|
|
|
public Float score(Map<String, String> featureMap) {
|
|
|
|
|
|
- double[] values = new double[features.length];
|
|
|
- for (int i = 0; i < features.length; i++) {
|
|
|
- double v = NumberUtils.toDouble(featureMap.getOrDefault(features[i], "0.0"), 0.0);
|
|
|
- values[i] = v;
|
|
|
+ try {
|
|
|
+ float[] values = new float[features.length];
|
|
|
+ for (int i = 0; i < features.length; i++) {
|
|
|
+ float v = NumberUtils.toFloat(featureMap.getOrDefault(features[i], "0.0"), 0.0f);
|
|
|
+ values[i] = v;
|
|
|
+ }
|
|
|
+ DMatrix dm = new DMatrix(values, 1, features.length, 0.0f);
|
|
|
+ float[][] result = model._booster().predict(dm, false, 100);
|
|
|
+ return result[0][0];
|
|
|
+ } catch (Exception e) {
|
|
|
+ return 0f;
|
|
|
}
|
|
|
-
|
|
|
- Vector v = Vectors.dense(values);
|
|
|
- double score = model.predict(v);
|
|
|
- return (float) score;
|
|
|
}
|
|
|
|
|
|
@Override
|