Java
Quick start
To apply a previously trained CatBoost model in Java:
-
Install the package using a package manager.
Note that the package contains native code shared libraries inside. The supported platforms are:
Operating system CPU architectures GPU support using CUDA macOS (versions currently supported by Apple) x86_64 and arm64 no Linux (compatible with manylinux2014 platform tag ) x86_64 and aarch64 yes Windows 10 and 11 x86_64 yes Note
Release binaries for x86_64 CPU architectures are built with SIMD extensions SSE2, SSE3, SSSE3, SSE4 enabled. If you need to run CatBoost on older CPUs that do not support these instruction sets build CatBoost artifacts yourself
Note
This version has CUDA-enabled GPU support out-of-the-box on Linux and Windows.
As of CatBoost 1.2.8, devices with CUDA compute capability >= 3.5 are supported in released packages.
All necessary CUDA libraries are statically linked in the released Linux and Windows binaries, the only installation necessary is the appropriate version of the CUDA driver.
Inference on CUDA-enabled GPUs requires NVIDIA Driver of version 450.80.02 or higher.
Add the following block to the dependencies section of the pom.xml file for Maven:
<!-- https://mvnrepository.com/artifact/ai.catboost/catboost-prediction --> <dependency> <groupId>ai.catboost</groupId> <artifactId>catboost-prediction</artifactId> <version>source_version</version> </dependency>
source_version
should be set to one of the main CatBoost releases. Available versions can also be checked on the Maven repository site. -
Load the trained model:
import ai.catboost.CatBoostModel; import ai.catboost.CatBoostPredictions; CatBoostModel model = CatBoostModel.loadModel("model.cbm");
-
Apply the model:
CatBoostPredictions prediction = model.predict(new float[]{0.1f, 0.3f, 0.2f}, new String[]{"foo", "bar", "baz"}); // assuming that this is a regression task System.out.print("model value is " + String.valueOf(prediction.get(0, 0));
Provided classes
Class | Description |
---|---|
CatBoostModel | Basic model application methods. |
CatBoostPredictions | A wrapper that provides methods for making convenient predictions for certain classes. |