treelite
Functions
Model_builder

Functions

int TreeliteCreateTreeBuilder (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, double 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, double leaf_value)
 Turn an empty node into a leaf node. More...
 
int TreeliteTreeBuilderSetLeafVectorNode (TreeBuilderHandle handle, int node_key, const double *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_output_group, int random_forest_flag, 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

Model builder interface: build trees incrementally

Function Documentation

int TreeliteCreateModelBuilder ( int  num_feature,
int  num_output_group,
int  random_forest_flag,
ModelBuilderHandle out 
)

Create a new model builder.

Parameters
num_featurenumber of features used in model being built. We assume that all feature indices are between 0 and (num_feature - 1).
num_output_groupnumber of output groups. Set to 1 for binary classification and regression; >1 for multiclass classification
random_forest_flagwhether the model is a random forest. Set to 0 if the model is gradient boosted trees. Any nonzero value shall indicate that the model is a random forest.
outnewly created model builder
Returns
0 for success; -1 for failure

Definition at line 478 of file c_api.cc.

int TreeliteCreateTreeBuilder ( TreeBuilderHandle out)

Create a new tree builder.

Parameters
outnewly created tree builder
Returns
0 for success; -1 for failure

Definition at line 373 of file c_api.cc.

int TreeliteDeleteModelBuilder ( ModelBuilderHandle  handle)

Delete a model builder from memory.

Parameters
handlemodel builder to remove
Returns
0 for success; -1 for failure

Definition at line 499 of file c_api.cc.

int TreeliteDeleteTreeBuilder ( TreeBuilderHandle  handle)

Delete a tree builder from memory.

Parameters
handletree builder to remove
Returns
0 for success; -1 for failure

Definition at line 380 of file c_api.cc.

int TreeliteModelBuilderCommitModel ( ModelBuilderHandle  handle,
ModelHandle out 
)

finalize the model and produce the in-memory representation

Parameters
handlemodel builder
outused to save handle to in-memory representation of the finished model
Returns
0 for success; -1 for failure

Definition at line 536 of file c_api.cc.

int TreeliteModelBuilderDeleteTree ( ModelBuilderHandle  handle,
int  index 
)

Remove a tree from the ensemble.

Parameters
handlemodel builder
indexindex of the tree that would be removed
Returns
0 for success; -1 for failure

Definition at line 528 of file c_api.cc.

int TreeliteModelBuilderGetTree ( ModelBuilderHandle  handle,
int  index,
TreeBuilderHandle out 
)

Get a reference to a tree in the ensemble.

Parameters
handlemodel builder
indexindex of the tree in the ensemble
outused to save reference to the tree
Returns
0 for success; -1 for failure

Definition at line 517 of file c_api.cc.

int TreeliteModelBuilderInsertTree ( ModelBuilderHandle  handle,
TreeBuilderHandle  tree_builder,
int  index 
)

Insert a tree at specified location.

Parameters
handlemodel builder
tree_builderbuilder for the tree to be inserted. The tree must not be part of any other existing tree ensemble. Note: The tree_builder argument will become unusuable after the tree insertion. Should you want to modify the tree afterwards, use GetTree(*) method to get a fresh handle to the tree.
indexindex of the element before which to insert the tree; use -1 to insert at the end
Returns
index of the new tree within the ensemble; -1 for failure

Definition at line 505 of file c_api.cc.

int TreeliteModelBuilderSetModelParam ( ModelBuilderHandle  handle,
const char *  name,
const char *  value 
)

Set a model parameter.

Parameters
handlemodel builder
namename of parameter
valuevalue of parameter
Returns
0 for success; -1 for failure

Definition at line 489 of file c_api.cc.

int TreeliteTreeBuilderCreateNode ( TreeBuilderHandle  handle,
int  node_key 
)

Create an empty node within a tree.

Parameters
handletree builder
node_keyunique integer key to identify the new node
Returns
0 for success; -1 for failure

Definition at line 386 of file c_api.cc.

int TreeliteTreeBuilderDeleteNode ( TreeBuilderHandle  handle,
int  node_key 
)

Remove a node from a tree.

Parameters
handletree builder
node_keyunique integer key to identify the node to be removed
Returns
0 for success; -1 for failure

Definition at line 394 of file c_api.cc.

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.

Parameters
handletree builder
node_keyunique integer key to identify the node being modified; this node needs to be empty
feature_idid of feature
left_categorieslist of categories belonging to the left child
left_categories_lenlength of left_cateogries
default_leftdefault direction for missing values
left_child_keyunique integer key to identify the left child node
right_child_keyunique integer key to identify the right child node
Returns
0 for success; -1 for failure

Definition at line 430 of file c_api.cc.

int TreeliteTreeBuilderSetLeafNode ( TreeBuilderHandle  handle,
int  node_key,
double  leaf_value 
)

Turn an empty node into a leaf node.

Parameters
handletree builder
node_keyunique integer key to identify the node being modified; this node needs to be empty
leaf_valueleaf value (weight) of the leaf node
Returns
0 for success; -1 for failure

Definition at line 453 of file c_api.cc.

int TreeliteTreeBuilderSetLeafVectorNode ( TreeBuilderHandle  handle,
int  node_key,
const double *  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.

Parameters
handletree builder
node_keyunique integer key to identify the node being modified; this node needs to be empty
leaf_vectorleaf vector of the leaf node
leaf_vector_lenlength of leaf_vector
Returns
0 for success; -1 for failure

Definition at line 463 of file c_api.cc.

int TreeliteTreeBuilderSetNumericalTestNode ( TreeBuilderHandle  handle,
int  node_key,
unsigned  feature_id,
const char *  opname,
double  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.

Parameters
handletree builder
node_keyunique integer key to identify the node being modified; this node needs to be empty
feature_idid of feature
opnamebinary operator to use in the test
thresholdthreshold value
default_leftdefault direction for missing values
left_child_keyunique integer key to identify the left child node
right_child_keyunique integer key to identify the right child node
Returns
0 for success; -1 for failure

Definition at line 410 of file c_api.cc.

int TreeliteTreeBuilderSetRootNode ( TreeBuilderHandle  handle,
int  node_key 
)

Set a node as the root of a tree.

Parameters
handletree builder
node_keyunique integer key to identify the root node
Returns
0 for success; -1 for failure

Definition at line 402 of file c_api.cc.