Runtime API of Treelite Python package.
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
to 0
. Disabling thread pinning is recommended when
using Treelite in multi-threaded applications.
global_bias
¶Query global bias of the model
leaf_output_type
¶Query threshold type of the model
num_class
¶Query number of output groups of the model
num_feature
¶Query number of features used in the model
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.
sigmoid_alpha
¶Query sigmoid alpha of the model
threshold_type
¶Query threshold type of the model
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.
data (str
/ numpy.ndarray
/ scipy.sparse.csr_matrix
/ pandas.DataFrame
) – Data source. When data is str
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 to None
,
numpy.nan
will be used.
verbose (bool
, optional) – Whether to print extra messages during construction
feature_names (list
, optional) – Human-readable names for features
feature_types (list
, optional) – Types for features
nthread (int
, optional) – Number of threads
treelite_runtime.
TreeliteRuntimeError
¶Error thrown by Treelite runtime