Predictor
implements Serializable, KryoSerializable¶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 – error during loading the shared lib
GetGlobalBias
()¶Get global bias which adjusting predicted margin scores.
Value of global bias
GetNumClass
()¶Get the number of classes for the compiled model. This number is 1 for tasks other than multi-class classification.
Number of classes
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
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
finalize
()¶predict
(DMatrix batch, boolean verbose, boolean pred_margin)¶Perform batch prediction with a 2D 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.
batch – a data matrix of type DMatrix
verbose – whether to print extra diagnostic messages
pred_margin – whether to predict probabilities or raw margin scores
Resulting predictions, of dimension [num_row]*[num_class]
read
(Kryo kryo, Input in)¶write
(Kryo kryo, Output out)¶