Treelite
Typedefs | Functions
c_api.h File Reference

C API of Treelite, used for interfacing with other languages This header is excluded from the runtime. More...

#include "c_api_common.h"
Include dependency graph for c_api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void * ModelHandle
 handle to a decision tree ensemble model
 
typedef void * TreeBuilderHandle
 handle to tree builder class
 
typedef void * ModelBuilderHandle
 handle to ensemble builder class
 
typedef void * AnnotationHandle
 handle to branch annotation data
 
typedef void * CompilerHandle
 handle to compiler class
 
typedef void * ValueHandle
 handle to a polymorphic value type, used in the model builder API
 

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 TreeliteCompilerCreate (const char *name, CompilerHandle *out)
 create a compiler with a given name More...
 
int TreeliteCompilerSetParam (CompilerHandle handle, const char *name, const char *value)
 set a parameter for a compiler More...
 
int TreeliteCompilerGenerateCode (CompilerHandle compiler, ModelHandle model, int verbose, 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 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 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 TreeliteFreeModel (ModelHandle handle)
 delete model from memory 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, 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...
 

Detailed Description

C API of Treelite, used for interfacing with other languages This header is excluded from the runtime.

Copyright (c) 2017-2020 by Contributors

Author
Hyunsu Cho

Definition in file c_api.h.