Package biz.k11i.xgboost
Class Predictor
- java.lang.Object
-
- biz.k11i.xgboost.Predictor
-
- All Implemented Interfaces:
java.io.Serializable
public class Predictor extends java.lang.Object implements java.io.SerializablePredicts using the Xgboost model.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classPredictor.ModelParamParameters.
-
Field Summary
Fields Modifier and Type Field Description private floatbase_scoreprivate GradBoostergbmprivate Predictor.ModelParammparamprivate java.lang.Stringname_gbmprivate java.lang.Stringname_objprivate ObjFunctionobjprivate SparkModelParamsparkModelParam
-
Constructor Summary
Constructors Constructor Description Predictor(java.io.InputStream in)Predictor(java.io.InputStream in, PredictorConfiguration configuration)Instantiates with the Xgboost model
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetBaseScore()GradBoostergetBooster()intgetNumClass()Returns number of class.java.lang.StringgetObjName()SparkModelParamgetSparkModelParam()(package private) voidinitObjFunction(PredictorConfiguration configuration)(package private) voidinitObjGbm()private booleanisBeforeOrEqual12()Used e.g.float[]predict(FVec feat)Generates predictions for given feature vector.float[]predict(FVec feat, boolean output_margin)Generates predictions for given feature vector.float[]predict(FVec feat, boolean output_margin, int ntree_limit)Generates predictions for given feature vector.float[]predict(FVec feat, float base_margin)Generates predictions for given feature vector.float[]predict(FVec feat, float base_margin, int ntree_limit)Generates predictions for given feature vector.int[]predictLeaf(FVec feat)Predicts leaf index of each tree.int[]predictLeaf(FVec feat, int ntree_limit)Predicts leaf index of each tree.java.lang.String[]predictLeafPath(FVec feat)Predicts path to leaf of each tree.java.lang.String[]predictLeafPath(FVec feat, int ntree_limit)Predicts path to leaf of each tree.(package private) float[]predictRaw(FVec feat, int ntree_limit, float base_score)floatpredictSingle(FVec feat)Generates a prediction for given feature vector.floatpredictSingle(FVec feat, boolean output_margin)Generates a prediction for given feature vector.floatpredictSingle(FVec feat, boolean output_margin, int ntree_limit)Generates a prediction for given feature vector.(package private) floatpredictSingleRaw(FVec feat, int ntree_limit)(package private) voidreadParam(ModelReader reader)
-
-
-
Field Detail
-
mparam
private Predictor.ModelParam mparam
-
sparkModelParam
private SparkModelParam sparkModelParam
-
name_obj
private java.lang.String name_obj
-
name_gbm
private java.lang.String name_gbm
-
obj
private ObjFunction obj
-
gbm
private GradBooster gbm
-
base_score
private float base_score
-
-
Constructor Detail
-
Predictor
public Predictor(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
Predictor
public Predictor(java.io.InputStream in, PredictorConfiguration configuration) throws java.io.IOExceptionInstantiates with the Xgboost model- Parameters:
in- input streamconfiguration- configuration- Throws:
java.io.IOException- If an I/O error occurs
-
-
Method Detail
-
readParam
void readParam(ModelReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
initObjFunction
void initObjFunction(PredictorConfiguration configuration)
-
initObjGbm
void initObjGbm()
-
predict
public float[] predict(FVec feat)
Generates predictions for given feature vector.- Parameters:
feat- feature vector- Returns:
- prediction values
-
predict
public float[] predict(FVec feat, boolean output_margin)
Generates predictions for given feature vector.- Parameters:
feat- feature vectoroutput_margin- whether to only predict margin value instead of transformed prediction- Returns:
- prediction values
-
predict
public float[] predict(FVec feat, float base_margin)
Generates predictions for given feature vector.- Parameters:
feat- feature vectorbase_margin- predict with base margin for each prediction- Returns:
- prediction values
-
predict
public float[] predict(FVec feat, float base_margin, int ntree_limit)
Generates predictions for given feature vector.- Parameters:
feat- feature vectorbase_margin- predict with base margin for each predictionntree_limit- limit the number of trees used in prediction- Returns:
- prediction values
-
predict
public float[] predict(FVec feat, boolean output_margin, int ntree_limit)
Generates predictions for given feature vector.- Parameters:
feat- feature vectoroutput_margin- whether to only predict margin value instead of transformed predictionntree_limit- limit the number of trees used in prediction- Returns:
- prediction values
-
predictRaw
float[] predictRaw(FVec feat, int ntree_limit, float base_score)
-
predictSingle
public float predictSingle(FVec feat)
Generates a prediction for given feature vector.This method only works when the model outputs single value.
- Parameters:
feat- feature vector- Returns:
- prediction value
-
predictSingle
public float predictSingle(FVec feat, boolean output_margin)
Generates a prediction for given feature vector.This method only works when the model outputs single value.
- Parameters:
feat- feature vectoroutput_margin- whether to only predict margin value instead of transformed prediction- Returns:
- prediction value
-
predictSingle
public float predictSingle(FVec feat, boolean output_margin, int ntree_limit)
Generates a prediction for given feature vector.This method only works when the model outputs single value.
- Parameters:
feat- feature vectoroutput_margin- whether to only predict margin value instead of transformed predictionntree_limit- limit the number of trees used in prediction- Returns:
- prediction value
-
predictSingleRaw
float predictSingleRaw(FVec feat, int ntree_limit)
-
predictLeaf
public int[] predictLeaf(FVec feat)
Predicts leaf index of each tree.- Parameters:
feat- feature vector- Returns:
- leaf indexes
-
predictLeaf
public int[] predictLeaf(FVec feat, int ntree_limit)
Predicts leaf index of each tree.- Parameters:
feat- feature vectorntree_limit- limit, 0 for all- Returns:
- leaf indexes
-
predictLeafPath
public java.lang.String[] predictLeafPath(FVec feat)
Predicts path to leaf of each tree.- Parameters:
feat- feature vector- Returns:
- leaf paths
-
predictLeafPath
public java.lang.String[] predictLeafPath(FVec feat, int ntree_limit)
Predicts path to leaf of each tree.- Parameters:
feat- feature vectorntree_limit- limit, 0 for all- Returns:
- leaf paths
-
getSparkModelParam
public SparkModelParam getSparkModelParam()
-
getNumClass
public int getNumClass()
Returns number of class.- Returns:
- number of class
-
isBeforeOrEqual12
private boolean isBeforeOrEqual12()
Used e.g. for the change od floating point operation order in between xgboost 1.2 and 1.3- Returns:
- True if the booster was build with xgboost version <= 1.2.
-
getBooster
public GradBooster getBooster()
-
getObjName
public java.lang.String getObjName()
-
getBaseScore
public float getBaseScore()
-
-