Package ai.catboost
Class CatBoostModel
java.lang.Object
ai.catboost.CatBoostModel
- All Implemented Interfaces:
AutoCloseable
CatBoost model, supports basic model application.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classstatic classstatic final classstatic enumstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]private List<CatBoostModel.Feature> private longprivate static CatBoostJNIprivate intprivate intprivate intprivate intprivate intprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()private voiddispose()protected voidfinalize()String[]intintintintintintstatic inthashCategoricalFeature(String catFeature) Hash categorical feature.static int[]hashCategoricalFeatures(String[] catFeatures) Hash array of categorical features.static voidhashCategoricalFeatures(String[] catFeatures, int[] hashes) Hash array of categorical features.static CatBoostModelloadModel(byte[] serializedModel) Load CatBoost model serialized in an array.static CatBoostModelLoad CatBoost model serialized in an array.static CatBoostModelloadModel(InputStream in) Load CatBoost model from stream.static CatBoostModelloadModel(InputStream in, String modelFormat) Load CatBoost model from stream.static CatBoostModelLoad CatBoost model from file modelPath.static CatBoostModelLoad CatBoost model from file modelPath.predict(float[][] numericFeatures, int[][] catFeatureHashes) Same aspredict(float[][], String[][], CatBoostPredictions), but returns predictions instead of taking it as the last parameter.voidpredict(float[][] numericFeatures, int[][] catFeatureHashes, CatBoostPredictions prediction) Same aspredict(float[][], String[][], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).predict(float[][] numericFeatures, int[][] catFeatureHashes, String[][] textFeatures, float[][][] embeddingFeatures) Same aspredict(float[][], String[][], String[][], float[][][], CatBoostPredictions), but returns predictions instead of taking it as the last parameter.voidpredict(float[][] numericFeatures, int[][] catFeatureHashes, String[][] textFeatures, float[][][] embeddingFeatures, CatBoostPredictions prediction) Same aspredict(float[][], String[][], String[][], float[][][], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).Same aspredict(float[][], String[][], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.voidpredict(float[][] numericFeatures, String[][] catFeatures, CatBoostPredictions prediction) Apply model to a batch of objects.predict(float[][] numericFeatures, String[][] catFeatures, String[][] textFeatures, float[][][] embeddingFeatures) Same aspredict(float[][], String[][], String[][], float[][][], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.voidpredict(float[][] numericFeatures, String[][] catFeatures, String[][] textFeatures, float[][][] embeddingFeatures, CatBoostPredictions prediction) Apply model to a batch of objects.predict(float[] numericFeatures, int[] catFeatureHashes) Same aspredict(float[], int[], CatBoostPredictions), but returns prediction instead of taking it as third parameter.voidpredict(float[] numericFeatures, int[] catFeatureHashes, CatBoostPredictions prediction) Same aspredict(float[], String[], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).predict(float[] numericFeatures, int[] catFeatureHashes, String[] textFeatures, float[][] embeddingFeatures) Same aspredict(float[], int[], String[], float[][], CatBoostPredictions), but returns prediction instead of taking it as third parameter.voidpredict(float[] numericFeatures, int[] catFeatureHashes, String[] textFeatures, float[][] embeddingFeatures, CatBoostPredictions prediction) Same aspredict(float[], String[], String[], float[][], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).Same aspredict(float[], String[], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.voidpredict(float[] numericFeatures, String[] catFeatures, CatBoostPredictions prediction) Apply model to object defined by features.predict(float[] numericFeatures, String[] catFeatures, String[] textFeatures, float[][] embeddingFeatures) Same aspredict(float[], String[], String[], float[][], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.voidpredict(float[] numericFeatures, String[] catFeatures, String[] textFeatures, float[][] embeddingFeatures, CatBoostPredictions prediction) Apply model to object defined by features.predictTransposed(float[][] numericFeatures) Apply model to a batch of objects, but features of objects used in column format.voidsetEvaluatorType(CatBoostModel.FormulaEvaluatorType evaluatorType)
-
Field Details
-
handle
private long handle -
predictionDimension
private int predictionDimension -
treeCount
private int treeCount -
usedNumericFeatureCount
private int usedNumericFeatureCount -
usedCategoricFeatureCount
private int usedCategoricFeatureCount -
usedTextFeatureCount
private int usedTextFeatureCount -
usedEmbeddingFeatureCount
private int usedEmbeddingFeatureCount -
featureNames
-
metadata
-
features
-
implLibrary
-
-
Constructor Details
-
CatBoostModel
- Throws:
CatBoostError
-
-
Method Details
-
loadModel
Load CatBoost model from file modelPath.- Parameters:
modelPath- Path to the model.- Returns:
- CatBoost model.
- Throws:
CatBoostError- When failed to load model.
-
loadModel
@Nonnull public static CatBoostModel loadModel(@Nonnull String modelPath, @Nonnull String modelFormat) throws CatBoostError Load CatBoost model from file modelPath.- Parameters:
modelPath- Path to the model.modelFormat- Model file format (bin or json)- Returns:
- CatBoost model.
- Throws:
CatBoostError- When failed to load model.
-
loadModel
@Nonnull public static CatBoostModel loadModel(@Nonnull byte[] serializedModel) throws CatBoostError Load CatBoost model serialized in an array.- Parameters:
serializedModel- Byte array containing model.- Returns:
- CatBoost model.
- Throws:
CatBoostError- When failed to load model.
-
loadModel
@Nonnull public static CatBoostModel loadModel(@Nonnull byte[] serializedModel, @Nonnull String modelFormat) throws CatBoostError Load CatBoost model serialized in an array.- Parameters:
serializedModel- Byte array containing model.modelFormat- Model file format (bin or json)- Returns:
- CatBoost model.
- Throws:
CatBoostError- When failed to load model.
-
loadModel
Load CatBoost model from stream.- Parameters:
in- Input stream containing model.- Returns:
- CatBoost model.
- Throws:
CatBoostError- When failed to load model.IOException- When failed to read model from file.
-
loadModel
@Nonnull public static CatBoostModel loadModel(InputStream in, @Nonnull String modelFormat) throws CatBoostError, IOException Load CatBoost model from stream.- Parameters:
in- Input stream containing model.modelFormat- Model file format (bin or json)- Returns:
- CatBoost model.
- Throws:
CatBoostError- When failed to load model.IOException- When failed to read model from file.
-
hashCategoricalFeature
Hash categorical feature.- Parameters:
catFeature- String representation of categorical feature.- Returns:
- Hash for categorical feature.
- Throws:
CatBoostError- In case of error within native library.
-
hashCategoricalFeatures
public static void hashCategoricalFeatures(@Nonnull String[] catFeatures, @Nonnull int[] hashes) throws CatBoostError Hash array of categorical features. May be cheaper to call this function once instead of callinghashCategoricalFeature(String)for each categorical feature in array.- Parameters:
catFeatures- Array of categorical features.hashes- Array of hashes of categorical features.- Throws:
CatBoostError- In case of error within native library.
-
hashCategoricalFeatures
@Nonnull public static int[] hashCategoricalFeatures(@Nonnull String[] catFeatures) throws CatBoostError Hash array of categorical features.- Parameters:
catFeatures- Array of categorical features.- Returns:
- Array of hashes of categorical features.
- Throws:
CatBoostError- In case of error within native library.
-
getSupportedEvaluatorTypes
- Throws:
CatBoostError
-
setEvaluatorType
- Throws:
CatBoostError
-
getEvaluatorType
public CatBoostModel.FormulaEvaluatorType getEvaluatorType() throws CatBoostError, IllegalArgumentException -
getPredictionDimension
public int getPredictionDimension()- Returns:
- Dimension of model prediction.
-
getTreeCount
public int getTreeCount()- Returns:
- Number of trees in model.
-
getUsedNumericFeatureCount
public int getUsedNumericFeatureCount()- Returns:
- Number of numeric features used by the model.
-
getUsedCategoricFeatureCount
public int getUsedCategoricFeatureCount()- Returns:
- Number of categorical features used by the model.
-
getUsedTextFeatureCount
public int getUsedTextFeatureCount()- Returns:
- Number of text features used by the model.
-
getUsedEmbeddingFeatureCount
public int getUsedEmbeddingFeatureCount()- Returns:
- Number of embedding features used by the model.
-
getFeatureNames
- Returns:
- Names of features used by the model.
-
getMetadata
- Returns:
- A map of metadata
-
getFeatures
- Returns:
- A list of feature metadata, sorted by flat index.
-
predict
public void predict(@Nullable float[] numericFeatures, @Nullable String[] catFeatures, @Nonnull CatBoostPredictions prediction) throws CatBoostError Apply model to object defined by features.- Parameters:
numericFeatures- Numeric features.catFeatures- Categoric features.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
public void predict(@Nullable float[] numericFeatures, @Nullable String[] catFeatures, @Nullable String[] textFeatures, @Nullable float[][] embeddingFeatures, @Nonnull CatBoostPredictions prediction) throws CatBoostError Apply model to object defined by features.- Parameters:
numericFeatures- Numeric features.catFeatures- Categoric features.textFeatures- Text features.embeddingFeatures- Embedding features.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[] numericFeatures, @Nullable String[] catFeatures) throws CatBoostError Same aspredict(float[], String[], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.- Parameters:
numericFeatures- Numeric features.catFeatures- Categoric features.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[] numericFeatures, @Nullable String[] catFeatures, @Nullable String[] textFeatures, @Nullable float[][] embeddingFeatures) throws CatBoostError Same aspredict(float[], String[], String[], float[][], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.- Parameters:
numericFeatures- Numeric features.catFeatures- Categoric features.textFeatures- Text features.embeddingFeatures- Embedding features.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predict
public void predict(@Nullable float[] numericFeatures, @Nullable int[] catFeatureHashes, @Nonnull CatBoostPredictions prediction) throws CatBoostError Same aspredict(float[], String[], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
public void predict(@Nullable float[] numericFeatures, @Nullable int[] catFeatureHashes, @Nullable String[] textFeatures, @Nullable float[][] embeddingFeatures, @Nonnull CatBoostPredictions prediction) throws CatBoostError Same aspredict(float[], String[], String[], float[][], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.textFeatures- Text features.embeddingFeatures- Embedding features.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[] numericFeatures, @Nullable int[] catFeatureHashes) throws CatBoostError Same aspredict(float[], int[], CatBoostPredictions), but returns prediction instead of taking it as third parameter.- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[] numericFeatures, @Nullable int[] catFeatureHashes, @Nullable String[] textFeatures, @Nullable float[][] embeddingFeatures) throws CatBoostError Same aspredict(float[], int[], String[], float[][], CatBoostPredictions), but returns prediction instead of taking it as third parameter.- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.textFeatures- Text features.embeddingFeatures- Embedding features.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predict
public void predict(@Nullable float[][] numericFeatures, @Nullable String[][] catFeatures, @Nonnull CatBoostPredictions prediction) throws CatBoostError Apply model to a batch of objects.- Parameters:
numericFeatures- Numeric features matrix.catFeatures- Categoric features matrix.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
public void predict(@Nullable float[][] numericFeatures, @Nullable String[][] catFeatures, @Nullable String[][] textFeatures, @Nullable float[][][] embeddingFeatures, @Nonnull CatBoostPredictions prediction) throws CatBoostError Apply model to a batch of objects.- Parameters:
numericFeatures- Numeric features matrix.catFeatures- Categoric features matrix.textFeatures- Text features matrix.embeddingFeatures- Embedding features matrix.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[][] numericFeatures, @Nullable String[][] catFeatures) throws CatBoostError Same aspredict(float[][], String[][], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.- Parameters:
numericFeatures- Numeric features.catFeatures- Categoric features.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predictTransposed
@Nonnull public CatBoostPredictions predictTransposed(@Nonnull float[][] numericFeatures) throws CatBoostError Apply model to a batch of objects, but features of objects used in column format.- Parameters:
numericFeatures- numeric features in column format (row of matrix is one feature for all objects).- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[][] numericFeatures, @Nullable String[][] catFeatures, @Nullable String[][] textFeatures, @Nullable float[][][] embeddingFeatures) throws CatBoostError Same aspredict(float[][], String[][], String[][], float[][][], CatBoostPredictions), but returns prediction instead of taking it as the last parameter.- Parameters:
numericFeatures- Numeric features.catFeatures- Categoric features.textFeatures- Text features.embeddingFeatures- Embedding features.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predict
public void predict(@Nullable float[][] numericFeatures, @Nullable int[][] catFeatureHashes, @Nonnull CatBoostPredictions prediction) throws CatBoostError Same aspredict(float[][], String[][], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
public void predict(@Nullable float[][] numericFeatures, @Nullable int[][] catFeatureHashes, @Nullable String[][] textFeatures, @Nullable float[][][] embeddingFeatures, @Nonnull CatBoostPredictions prediction) throws CatBoostError Same aspredict(float[][], String[][], String[][], float[][][], CatBoostPredictions), but accept categoric features as hashes computed byhashCategoricalFeature(String).- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.textFeatures- Text features.embeddingFeatures- Embedding features.prediction- Model predictions.- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[][] numericFeatures, @Nullable int[][] catFeatureHashes) throws CatBoostError Same aspredict(float[][], String[][], CatBoostPredictions), but returns predictions instead of taking it as the last parameter.- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
predict
@Nonnull public CatBoostPredictions predict(@Nullable float[][] numericFeatures, @Nullable int[][] catFeatureHashes, @Nullable String[][] textFeatures, @Nullable float[][][] embeddingFeatures) throws CatBoostError Same aspredict(float[][], String[][], String[][], float[][][], CatBoostPredictions), but returns predictions instead of taking it as the last parameter.- Parameters:
numericFeatures- Numeric features.catFeatureHashes- Categoric feature hashes.textFeatures- Text features.embeddingFeatures- Embedding features.- Returns:
- Model predictions.
- Throws:
CatBoostError- In case of error within native library.
-
finalize
-
dispose
- Throws:
CatBoostError
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
CatBoostError
-