Treelite runtime API

Runtime API of Treelite Python package.

class treelite_runtime.Predictor(libpath, nthread=None, verbose=False)

Predictor class: loader for compiled shared libraries

  • libpath (str) – location of dynamic shared library (.dll/.so/.dylib)

  • nthread (int, optional) – number of worker threads to use; if unspecified, use maximum number of hardware threads

  • verbose (bool, optional) – Whether to print extra messages during construction

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.

  • dmat (object of type DMatrix) – batch of rows for which predictions will be made

  • verbose (bool, optional) – Whether to print extra messages during prediction

  • pred_margin (bool, optional) – whether to produce raw margins rather than transformed probabilities

property sigmoid_alpha

Query sigmoid alpha of the model

property threshold_type

Query threshold type of the model

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.

  • 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

exception treelite_runtime.TreeliteRuntimeError

Error thrown by Treelite runtime