C++
- Purpose
-
Apply the model in C++ format. The method is available within the output C++ file with the model description.
Note.The ApplyCatboostModel method is inferior in performance compared to the native CatBoost application methods, especially on large models and datasets.
Multiclassification models are not currently supported.
- Method call format
-
For datasets that contain only numerical features:
double ApplyCatboostModel(const std::vector<float>& features);
For datasets that contain both numerical and categorical features:
double ApplyCatboostModel(const std::vector<float>& floatFeatures, const std::vector<std::string>& catFeatures);
- Parameters
-
Parameter Possible types Description features (floatFeatures) float The list of numerical features.
catFeatures string The list of categorical features.
Parameter Possible types Description features (floatFeatures) float The list of numerical features.
catFeatures string The list of categorical features.
- Type of return value
-
Prediction of the model for the object with given features.
The result is identical to the code below but does not require the library linking (libcatboostmodel.<so|dll|dylib>
for Linux/macOS orlibcatboostmodel.dll
for Windows):For datasets that contain only numerical features:
#include <catboost/libs/model_interface/wrapped_calcer.h> double ApplyCatboostModel(const std::vector<float>& features) { ModelCalcerWrapper calcer("model.cbm"); return calcer.Calc(features, {}); }
For datasets that contain both numerical and categorical features:
#include <catboost/libs/model_interface/wrapped_calcer.h> double ApplyCatboostModel(const std::vector<float>& floatFeatures, const std::vector<std::string>& catFeatures) { ModelCalcerWrapper calcer("model.cbm"); return calcer.Calc(floatFeatures, catFeatures); }
- Compilers
-
For datasets that contain only numerical features:
C++11 with support of non-static data member initializers and extended initializer lists.
For datasets that contain both numerical and categorical features:
C++14 compiler with aggregate member initialization support. Tested with the following compilers:- Clang++ 3.8
- g++ 5.4.1 20160904