Treelite
Classes | Functions
frontend.h File Reference

Collection of front-end methods to load or construct ensemble model. More...

#include <treelite/base.h>
#include <string>
#include <memory>
#include <vector>
#include <cstdint>
#include "frontend_impl.h"
Include dependency graph for frontend.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Value
 
class  TreeBuilder
 tree builder class More...
 
class  ModelBuilder
 model builder class More...
 

Functions

std::unique_ptr< treelite::ModelLoadLightGBMModel (const char *filename)
 load a model file generated by LightGBM (Microsoft/LightGBM). The model file must contain a decision tree ensemble. More...
 
std::unique_ptr< treelite::ModelLoadLightGBMModelFromString (const char *model_str)
 Load a LightGBM model from a string. The string should be created with the model_to_string() method in LightGBM. More...
 
std::unique_ptr< treelite::ModelLoadXGBoostModel (const char *filename)
 load a model file generated by XGBoost (dmlc/xgboost). The model file must contain a decision tree ensemble. More...
 
std::unique_ptr< treelite::ModelLoadXGBoostModel (const void *buf, size_t len)
 load an XGBoost model from a memory buffer. More...
 
std::unique_ptr< treelite::ModelLoadXGBoostJSONModel (const char *filename)
 load a model file generated by XGBoost (dmlc/xgboost). The model file must contain a decision tree ensemble in the JSON format. More...
 
std::unique_ptr< treelite::ModelLoadXGBoostJSONModelString (const char *json_str, size_t length)
 load an XGBoost model from a JSON string More...
 
std::unique_ptr< treelite::ModelLoadSKLearnRandomForestRegressor (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 **weighted_n_node_samples, const double **impurity)
 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...
 
std::unique_ptr< treelite::ModelLoadSKLearnIsolationForest (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 **weighted_n_node_samples, const double **impurity, const double ratio_c)
 Load a scikit-learn isolation forest 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...
 
std::unique_ptr< treelite::ModelLoadSKLearnRandomForestClassifier (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 **weighted_n_node_samples, const double **impurity)
 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...
 
std::unique_ptr< treelite::ModelLoadSKLearnGradientBoostingRegressor (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 **weighted_n_node_samples, const double **impurity)
 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...
 
std::unique_ptr< treelite::ModelLoadSKLearnGradientBoostingClassifier (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 **weighted_n_node_samples, const double **impurity)
 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...
 

Detailed Description

Collection of front-end methods to load or construct ensemble model.

Copyright (c) 2017-2021 by Contributors

Author
Hyunsu Cho

Definition in file frontend.h.

Function Documentation

◆ LoadLightGBMModel()

std::unique_ptr< treelite::Model > LoadLightGBMModel ( const char *  filename)

load a model file generated by LightGBM (Microsoft/LightGBM). The model file must contain a decision tree ensemble.

Parameters
filenamename of model file
Returns
loaded model

Definition at line 28 of file lightgbm.cc.

◆ LoadLightGBMModelFromString()

std::unique_ptr< treelite::Model > LoadLightGBMModelFromString ( const char *  model_str)

Load a LightGBM model from a string. The string should be created with the model_to_string() method in LightGBM.

Parameters
model_strthe model string
Returns
loaded model

Definition at line 33 of file lightgbm.cc.

◆ LoadSKLearnGradientBoostingClassifier()

std::unique_ptr< treelite::Model > LoadSKLearnGradientBoostingClassifier ( 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 **  weighted_n_node_samples,
const double **  impurity 
)

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.

Parameters
n_estimatorsnumber of trees in the random forest
n_featuresnumber of features in the training data
n_classesnumber of classes in the target variable
node_countnode_count[i] stores the number of nodes in the i-th tree
children_leftchildren_left[i][k] stores the ID of the left child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
children_rightchildren_right[i][k] stores the ID of the right child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
featurefeature[i][k] stores the ID of the feature used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
thresholdthreshold[i][k] stores the threshold used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
valuevalue[i][k] stores the leaf output of node k of the i-th tree. This is only defined if node k is a leaf node.
n_node_samplesn_node_samples[i][k] stores the number of data samples associated with node k of the i-th tree.
weighted_n_node_samplesweighted_n_node_samples[i][k] stores the sum of weighted data samples associated with node k of the i-th tree.
impurityimpurity[i][k] stores the impurity measure (gini, entropy etc) associated with node k of the i-th tree.
Returns
loaded model

Definition at line 290 of file sklearn.cc.

◆ LoadSKLearnGradientBoostingRegressor()

std::unique_ptr< treelite::Model > LoadSKLearnGradientBoostingRegressor ( 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 **  weighted_n_node_samples,
const double **  impurity 
)

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.

Parameters
n_estimatorsnumber of trees in the random forest
n_featuresnumber of features in the training data
node_countnode_count[i] stores the number of nodes in the i-th tree
children_leftchildren_left[i][k] stores the ID of the left child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
children_rightchildren_right[i][k] stores the ID of the right child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
featurefeature[i][k] stores the ID of the feature used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
thresholdthreshold[i][k] stores the threshold used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
valuevalue[i][k] stores the leaf output of node k of the i-th tree. This is only defined if node k is a leaf node.
n_node_samplesn_node_samples[i][k] stores the number of data samples associated with node k of the i-th tree.
weighted_n_node_samplesweighted_n_node_samples[i][k] stores the sum of weighted data samples associated with node k of the i-th tree.
impurityimpurity[i][k] stores the impurity measure (gini, entropy etc) associated with node k of the i-th tree.
Returns
loaded model

Definition at line 212 of file sklearn.cc.

◆ LoadSKLearnIsolationForest()

std::unique_ptr< treelite::Model > LoadSKLearnIsolationForest ( 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 **  weighted_n_node_samples,
const double **  impurity,
const double  ratio_c 
)

Load a scikit-learn isolation forest 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.

Parameters
n_estimatorsnumber of trees in the isolation forest
n_featuresnumber of features in the training data
node_countnode_count[i] stores the number of nodes in the i-th tree
children_leftchildren_left[i][k] stores the ID of the left child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
children_rightchildren_right[i][k] stores the ID of the right child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
featurefeature[i][k] stores the ID of the feature used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
thresholdthreshold[i][k] stores the threshold used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
valuevalue[i][k] stores the expected isolation depth of node k of the i-th tree. This is only defined if node k is a leaf node.
n_node_samplesn_node_samples[i][k] stores the number of data samples associated with node k of the i-th tree.
weighted_n_node_samplesweighted_n_node_samples[i][k] stores the sum of weighted data samples associated with node k of the i-th tree.
impuritynot used, but must be passed as array of arrays for each tree and node.
ratio_cstandardizing constant to use for calculation of the anomaly score.
Returns
loaded model

Definition at line 103 of file sklearn.cc.

◆ LoadSKLearnRandomForestClassifier()

std::unique_ptr< treelite::Model > LoadSKLearnRandomForestClassifier ( 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 **  weighted_n_node_samples,
const double **  impurity 
)

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).

Parameters
n_estimatorsnumber of trees in the random forest
n_featuresnumber of features in the training data
n_classesnumber of classes in the target variable
node_countnode_count[i] stores the number of nodes in the i-th tree
children_leftchildren_left[i][k] stores the ID of the left child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
children_rightchildren_right[i][k] stores the ID of the right child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
featurefeature[i][k] stores the ID of the feature used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
thresholdthreshold[i][k] stores the threshold used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
valuevalue[i][k] stores the leaf output of node k of the i-th tree. This is only defined if node k is a leaf node.
n_node_samplesn_node_samples[i][k] stores the number of data samples associated with node k of the i-th tree.
weighted_n_node_samplesweighted_n_node_samples[i][k] stores the sum of weighted data samples associated with node k of the i-th tree.
impurityimpurity[i][k] stores the impurity measure (gini, entropy etc) associated with node k of the i-th tree.
Returns
loaded model

Definition at line 195 of file sklearn.cc.

◆ LoadSKLearnRandomForestRegressor()

std::unique_ptr< treelite::Model > LoadSKLearnRandomForestRegressor ( 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 **  weighted_n_node_samples,
const double **  impurity 
)

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).

Parameters
n_estimatorsnumber of trees in the random forest
n_featuresnumber of features in the training data
node_countnode_count[i] stores the number of nodes in the i-th tree
children_leftchildren_left[i][k] stores the ID of the left child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
children_rightchildren_right[i][k] stores the ID of the right child node of node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
featurefeature[i][k] stores the ID of the feature used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
thresholdthreshold[i][k] stores the threshold used in the binary tree split at node k of the i-th tree. This is only defined if node k is an internal (non-leaf) node.
valuevalue[i][k] stores the leaf output of node k of the i-th tree. This is only defined if node k is a leaf node.
n_node_samplesn_node_samples[i][k] stores the number of data samples associated with node k of the i-th tree.
weighted_n_node_samplesweighted_n_node_samples[i][k] stores the sum of weighted data samples associated with node k of the i-th tree.
impurityimpurity[i][k] stores the impurity measure (gini, entropy etc) associated with node k of the i-th tree.
Returns
loaded model

Definition at line 77 of file sklearn.cc.

◆ LoadXGBoostJSONModel()

std::unique_ptr< treelite::Model > LoadXGBoostJSONModel ( const char *  filename)

load a model file generated by XGBoost (dmlc/xgboost). The model file must contain a decision tree ensemble in the JSON format.

Parameters
filenamename of model file
Returns
loaded model

Definition at line 41 of file xgboost_json.cc.

◆ LoadXGBoostJSONModelString()

std::unique_ptr< treelite::Model > LoadXGBoostJSONModelString ( const char *  json_str,
size_t  length 
)

load an XGBoost model from a JSON string

Parameters
json_strJSON char array
lengthlength of JSON char array
Returns
loaded model

Definition at line 81 of file xgboost_json.cc.

◆ LoadXGBoostModel() [1/2]

std::unique_ptr< treelite::Model > LoadXGBoostModel ( const char *  filename)

load a model file generated by XGBoost (dmlc/xgboost). The model file must contain a decision tree ensemble.

Parameters
filenamename of model file
Returns
loaded model

Definition at line 29 of file xgboost.cc.

◆ LoadXGBoostModel() [2/2]

std::unique_ptr< treelite::Model > LoadXGBoostModel ( const void *  buf,
size_t  len 
)

load an XGBoost model from a memory buffer.

Parameters
bufmemory buffer
lensize of memory buffer
Returns
loaded model

Definition at line 34 of file xgboost.cc.