Predictor
implements Serializable¶Treelite Predictor
Hyunsu Cho
Predictor
(String libpath, int nthread, boolean verbose)¶Create a Predictor by loading a shared library (dll/so/dylib). The library is expected to contain the compiled code for making prediction for a particular tree ensemble model. The predictor also spawns a fixed-size pool of worker threads, who will wait for prediction tasks. (Note that the worker threads will go to sleep when no prediction task is available, to free up CPU cycles for other processes.)
libpath – Path to the shared library
nthread – Number of workers threads to spawn. Set to -1 to use default, i.e., to launch as many threads as CPU cores available on the system. You are not allowed to launch more threads than CPU cores. Setting nthread=1
indicates that the main thread should be exclusively used.
verbose – Whether to print extra diagnostic messages
TreeliteError –
Created Predictor
GetGlobalBias
()¶Get global bias which adjusting predicted margin scores.
Value of global bias
GetNumFeature
()¶Get the number of features used by the compiled model. Call this method to allocate array for storing data entries of a single instance.
Number of features
GetNumOutputGroup
()¶Get the number of output groups for the compiled model. This number is 1 for tasks other than multi-class classification. For multi-class classification task, the number is equal to the number of classes.
Number of output groups
GetSigmoidAlpha
()¶Get alpha value in sigmoid transformation used to train the loaded model.
Alpha value of sigmoid transformation
dispose
()¶Destructor, to be called when the object is garbage collected
predict
(Data[] inst, boolean pred_margin)¶Perform single-instance prediction. Prediction is run by the calling thread.
inst – array of data entires comprising the instance
pred_margin – whether to predict a probability or a raw margin score
Resulting predictions, of dimension [num_output_group]
predict
(SparseBatch batch, boolean verbose, boolean pred_margin)¶Perform batch prediction with a 2D sparse data matrix. Worker threads will internally divide up work for batch prediction. Note that this function will be blocked by mutex when worker_thread > 1. In order to use multiple threads to process multiple prediction requests simultaneously, use Predictor.predict(Data[], boolean)
instead or keep worker_thread = 1.
batch – a SparseBatch
, representing a slice of a 2D sparse matrix
verbose – whether to print extra diagnostic messages
pred_margin – whether to predict probabilities or raw margin scores
Resulting predictions, of dimension [num_row]*[num_output_group]
predict
(DenseBatch batch, boolean verbose, boolean pred_margin)¶Perform batch prediction with a 2D dense data matrix. Worker threads will internally divide up work for batch prediction. Note that this function will be blocked by mutex when worker_thread > 1. In order to use multiple threads to process multiple prediction requests simultaneously, use Predictor.predict(Data[], boolean)
instead or keep worker_thread = 1.
batch – a DenseBatch
, representing a slice of a 2D dense matrix
verbose – whether to print extra diagnostic messages
pred_margin – whether to predict probabilities or raw margin scores
Resulting predictions, of dimension [num_row]*[num_output_group]