Treelite runtime API
Runtime API of Treelite Python package.
Classes:
|
Data matrix used in Treelite. |
|
Predictor class: loader for compiled shared libraries |
Exceptions:
Error thrown by Treelite runtime |
- class treelite_runtime.DMatrix(data, data_format=None, dtype=None, missing=None, feature_names=None, feature_types=None, verbose=False, nthread=None)
Data matrix used in Treelite.
- Parameters:
data (
str
/numpy.ndarray
/scipy.sparse.csr_matrix
/pandas.DataFrame
) – Data source. When data isstr
type, it indicates that data should be read from a file.data_format (
str
, optional) – Format of input data file. Applicable only when data is read from a file. If missing, the svmlight (.libsvm) format is assumed.dtype (
str
, optional) – If specified, the data will be casted into the corresponding data type.missing (
float
, optional) – Value in the data that represents a missing entry. If set toNone
,numpy.nan
will be used.verbose (
bool
, optional) – Whether to print extra messages during constructionfeature_names (
list
, optional) – Human-readable names for featuresfeature_types (
list
, optional) – Types for featuresnthread (
int
, optional) – Number of threads
- class treelite_runtime.Predictor(libpath, nthread=None, verbose=False)
Predictor class: loader for compiled shared libraries
Note
Treelite uses a custom thread pool which pins threads to CPU cores by default. To disable thread pinning, set the environment variable
TREELITE_BIND_THREADS
to0
. Disabling thread pinning is recommended when using Treelite in multi-threaded applications.- Parameters:
Attributes:
Query global bias of the model
Query threshold type of the model
Query number of output groups of the model
Query number of features used in the model
Query pred transform of the model
Query sigmoid alpha of the model
Query sigmoid alpha of the model
Query threshold type of the model
Methods:
predict
(dmat[, verbose, pred_margin])Perform batch prediction with a 2D sparse data matrix.
- property global_bias
Query global bias of the model
- property leaf_output_type
Query threshold type of the model
- property num_class
Query number of output groups of the model
- property num_feature
Query number of features used in the model
- property pred_transform
Query pred transform of the model
- predict(dmat, verbose=False, pred_margin=False)
Perform batch prediction with a 2D sparse data matrix. Worker threads will internally divide up work for batch prediction. Note that this function may be called by only one thread at a time.
- property ratio_c
Query sigmoid alpha of the model
- property sigmoid_alpha
Query sigmoid alpha of the model
- property threshold_type
Query threshold type of the model
- exception treelite_runtime.TreeliteRuntimeError
Error thrown by Treelite runtime