Treelite
|
C API of treelite, used for interfacing with other languages. More...
#include <treelite/annotator.h>
#include <treelite/c_api.h>
#include <treelite/c_api_error.h>
#include <treelite/compiler.h>
#include <treelite/compiler_param.h>
#include <treelite/data.h>
#include <treelite/filesystem.h>
#include <treelite/frontend.h>
#include <treelite/tree.h>
#include <treelite/math.h>
#include <treelite/gtil.h>
#include <treelite/logging.h>
#include <memory>
#include <algorithm>
#include <fstream>
#include <string>
#include <cstdio>
Go to the source code of this file.
Functions | |
int | TreeliteAnnotateBranch (ModelHandle model, DMatrixHandle dmat, int nthread, int verbose, AnnotationHandle *out) |
annotate branches in a given model using frequency patterns in the training data. More... | |
int | TreeliteAnnotationSave (AnnotationHandle handle, const char *path) |
save branch annotation to a JSON file More... | |
int | TreeliteAnnotationFree (AnnotationHandle handle) |
delete branch annotation from memory More... | |
int | TreeliteCompilerCreateV2 (const char *name, const char *params_json_str, CompilerHandle *out) |
Create a compiler with a given name. More... | |
int | TreeliteCompilerGenerateCodeV2 (CompilerHandle compiler, ModelHandle model, const char *dirpath) |
Generate prediction code from a tree ensemble model. The code will be C99 compliant. One header file (.h) will be generated, along with one or more source files (.c). More... | |
int | TreeliteCompilerFree (CompilerHandle handle) |
delete compiler from memory More... | |
int | TreeliteLoadLightGBMModel (const char *filename, ModelHandle *out) |
load a model file generated by LightGBM (Microsoft/LightGBM). The model file must contain a decision tree ensemble. More... | |
int | TreeliteLoadXGBoostModel (const char *filename, ModelHandle *out) |
load a model file generated by XGBoost (dmlc/xgboost). The model file must contain a decision tree ensemble. More... | |
int | TreeliteLoadXGBoostJSON (const char *filename, ModelHandle *out) |
load a json model file generated by XGBoost (dmlc/xgboost). The model file must contain a decision tree ensemble. More... | |
int | TreeliteLoadXGBoostJSONString (const char *json_str, size_t length, ModelHandle *out) |
load a model stored as JSON stringby XGBoost (dmlc/xgboost). The model json must contain a decision tree ensemble. More... | |
int | TreeliteLoadXGBoostModelFromMemoryBuffer (const void *buf, size_t len, ModelHandle *out) |
load an XGBoost model from a memory buffer. More... | |
int | TreeliteLoadSKLearnRandomForestRegressor (int n_estimators, int n_features, const int64_t *node_count, const int64_t **children_left, const int64_t **children_right, const int64_t **feature, const double **threshold, const double **value, const int64_t **n_node_samples, const double **impurity, ModelHandle *out) |
Load a scikit-learn random forest regressor model from a collection of arrays. Refer to https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html to learn the mearning of the arrays in detail. Note that this function can also be used to load an ensemble of extremely randomized trees (sklearn.ensemble.ExtraTreesRegressor). More... | |
int | TreeliteLoadSKLearnRandomForestClassifier (int n_estimators, int n_features, int n_classes, const int64_t *node_count, const int64_t **children_left, const int64_t **children_right, const int64_t **feature, const double **threshold, const double **value, const int64_t **n_node_samples, const double **impurity, ModelHandle *out) |
Load a scikit-learn random forest classifier model from a collection of arrays. Refer to https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html to learn the mearning of the arrays in detail. Note that this function can also be used to load an ensemble of extremely randomized trees (sklearn.ensemble.ExtraTreesClassifier). More... | |
int | TreeliteLoadSKLearnGradientBoostingRegressor (int n_estimators, int n_features, const int64_t *node_count, const int64_t **children_left, const int64_t **children_right, const int64_t **feature, const double **threshold, const double **value, const int64_t **n_node_samples, const double **impurity, ModelHandle *out) |
Load a scikit-learn gradient boosting regressor model from a collection of arrays. Refer to https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html to learn the mearning of the arrays in detail. More... | |
int | TreeliteLoadSKLearnGradientBoostingClassifier (int n_estimators, int n_features, int n_classes, const int64_t *node_count, const int64_t **children_left, const int64_t **children_right, const int64_t **feature, const double **threshold, const double **value, const int64_t **n_node_samples, const double **impurity, ModelHandle *out) |
Load a scikit-learn gradient boosting classifier model from a collection of arrays. Refer to https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html to learn the mearning of the arrays in detail. More... | |
int | TreeliteSerializeModel (const char *filename, ModelHandle handle) |
Serialize (persist) a model object to disk. More... | |
int | TreeliteDeserializeModel (const char *filename, ModelHandle *out) |
Deserialize (load) a model object from disk. More... | |
int | TreeliteDumpAsJSON (ModelHandle handle, int pretty_print, const char **out_json_str) |
Dump a model object as a JSON string. More... | |
int | TreeliteFreeModel (ModelHandle handle) |
delete model from memory More... | |
int | TreeliteGTILGetPredictOutputSize (ModelHandle handle, size_t num_row, size_t *out) |
int | TreeliteGTILPredict (ModelHandle handle, const float *input, size_t num_row, float *output, int pred_transform, size_t *out_result_size) |
int | TreeliteQueryNumTree (ModelHandle handle, size_t *out) |
Query the number of trees in the model. More... | |
int | TreeliteQueryNumFeature (ModelHandle handle, size_t *out) |
Query the number of features used in the model. More... | |
int | TreeliteQueryNumClass (ModelHandle handle, size_t *out) |
Query the number of classes of the model. (1 if the model is binary classifier or regressor) More... | |
int | TreeliteSetTreeLimit (ModelHandle handle, size_t limit) |
keep first N trees of model, limit must smaller than number of trees. More... | |
int | TreeliteTreeBuilderCreateValue (const void *init_value, const char *type, ValueHandle *out) |
Create a new Value object. Some model builder API functions accept this Value type to accommodate values of multiple types. More... | |
int | TreeliteTreeBuilderDeleteValue (ValueHandle handle) |
Delete a Value object from memory. More... | |
int | TreeliteCreateTreeBuilder (const char *threshold_type, const char *leaf_output_type, TreeBuilderHandle *out) |
Create a new tree builder. More... | |
int | TreeliteDeleteTreeBuilder (TreeBuilderHandle handle) |
Delete a tree builder from memory. More... | |
int | TreeliteTreeBuilderCreateNode (TreeBuilderHandle handle, int node_key) |
Create an empty node within a tree. More... | |
int | TreeliteTreeBuilderDeleteNode (TreeBuilderHandle handle, int node_key) |
Remove a node from a tree. More... | |
int | TreeliteTreeBuilderSetRootNode (TreeBuilderHandle handle, int node_key) |
Set a node as the root of a tree. More... | |
int | TreeliteTreeBuilderSetNumericalTestNode (TreeBuilderHandle handle, int node_key, unsigned feature_id, const char *opname, ValueHandle threshold, int default_left, int left_child_key, int right_child_key) |
Turn an empty node into a test node with numerical split. The test is in the form [feature value] OP [threshold]. Depending on the result of the test, either left or right child would be taken. More... | |
int | TreeliteTreeBuilderSetCategoricalTestNode (TreeBuilderHandle handle, int node_key, unsigned feature_id, const unsigned int *left_categories, size_t left_categories_len, int default_left, int left_child_key, int right_child_key) |
Turn an empty node into a test node with categorical split. A list defines all categories that would be classified as the left side. Categories are integers ranging from 0 to (n-1), where n is the number of categories in that particular feature. Let's assume n <= 64. More... | |
int | TreeliteTreeBuilderSetLeafNode (TreeBuilderHandle handle, int node_key, ValueHandle leaf_value) |
Turn an empty node into a leaf node. More... | |
int | TreeliteTreeBuilderSetLeafVectorNode (TreeBuilderHandle handle, int node_key, const ValueHandle *leaf_vector, size_t leaf_vector_len) |
Turn an empty node into a leaf vector node The leaf vector (collection of multiple leaf weights per leaf node) is useful for multi-class random forest classifier. More... | |
int | TreeliteCreateModelBuilder (int num_feature, int num_class, int average_tree_output, const char *threshold_type, const char *leaf_output_type, ModelBuilderHandle *out) |
Create a new model builder. More... | |
int | TreeliteModelBuilderSetModelParam (ModelBuilderHandle handle, const char *name, const char *value) |
Set a model parameter. More... | |
int | TreeliteDeleteModelBuilder (ModelBuilderHandle handle) |
Delete a model builder from memory. More... | |
int | TreeliteModelBuilderInsertTree (ModelBuilderHandle handle, TreeBuilderHandle tree_builder_handle, int index) |
Insert a tree at specified location. More... | |
int | TreeliteModelBuilderGetTree (ModelBuilderHandle handle, int index, TreeBuilderHandle *out) |
Get a reference to a tree in the ensemble. More... | |
int | TreeliteModelBuilderDeleteTree (ModelBuilderHandle handle, int index) |
Remove a tree from the ensemble. More... | |
int | TreeliteModelBuilderCommitModel (ModelBuilderHandle handle, ModelHandle *out) |
finalize the model and produce the in-memory representation More... | |
C API of treelite, used for interfacing with other languages.
Copyright (c) 2017-2021 by Contributors
Definition in file c_api.cc.