Predictor

public class Predictor implements Serializable, KryoSerializable

Treelite Predictor

Author

Hyunsu Cho

Constructors

Predictor

public 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.)

Parameters
  • 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

Throws
  • TreeliteError – error during loading the shared lib

Methods

GetGlobalBias

public float GetGlobalBias()

Get global bias which adjusting predicted margin scores.

Returns

Value of global bias

GetNumClass

public int GetNumClass()

Get the number of classes for the compiled model. This number is 1 for tasks other than multi-class classification.

Returns

Number of classes

GetNumFeature

public int 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.

Returns

Number of features

GetPredTransform

public String GetPredTransform()

Get name of post prediction transformation used to train the loaded model.

Returns

Name of (post-)prediction transformation

GetSigmoidAlpha

public float GetSigmoidAlpha()

Get alpha value in sigmoid transformation used to train the loaded model.

Returns

Alpha value of sigmoid transformation

dispose

public synchronized void dispose()

Destructor, to be called when the object is garbage collected

finalize

protected void finalize()

predict

public INDArray 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.

Parameters
  • batch – a data matrix of type DMatrix

  • verbose – whether to print extra diagnostic messages

  • pred_margin – whether to predict probabilities or raw margin scores

Returns

Resulting predictions, of dimension [num_row]*[num_class]

read

public void read(Kryo kryo, Input in)

write

public void write(Kryo kryo, Output out)