mojolearn.HostForest#
- class mojolearn.HostForest(*, estimator, offsets, colid, quesval, left_child, leaves, n_features, n_trees, num_outputs, classes=None, device=None, inference_engine='sequential')[source]#
Bases:
objectA saved random forest or extra-trees model that predicts on the CPU.
Build one with
HostForest.from_file(path)from a file written byRandomForestClassifier.save,RandomForestRegressor.save,ExtraTreesClassifier.saveorExtraTreesRegressor.save. Prediction runs the inference engine the file names (‘sequential’ or ‘parallel_groves’) and returns what the GPU estimator returns for the same file: random forest probabilities and regression values as float32, extra-trees probabilities and regression values as float64. The model arrays are used exactly as saved, never cast; a file whose tree arrays are inconsistent raisesValueError.- Variables:
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).random((1000, 8), dtype=np.float32) >>> y = X[:, 0] * 2.0 >>> mojolearn.RandomForestRegressor(n_estimators=20).fit(X, y).save("rf.npz") >>> pred = mojolearn.HostForest.from_file("rf.npz").predict(X)
- __init__(*, estimator, offsets, colid, quesval, left_child, leaves, n_features, n_trees, num_outputs, classes=None, device=None, inference_engine='sequential')[source]#
Methods
from_file(path)Load a forest from a file written by a random forest or extra-trees
save.SHA-256 hex digest of the model arrays' bytes, in save order.
predict(X)Predict with the saved model.
Class probabilities, for classifier models only.
Attributes
'sequential' or 'parallel_groves'.
Number of trees in the model.
- classmethod from_file(path)[source]#
Load a forest from a file written by a random forest or extra-trees
save.The model predicts through the inference engine the file names. A model saved with
inference_engine='parallel_groves'must have been saved undernumeric_mode='identical'; otherwise this raisesValueError, because the CPU engine computesidenticalresults only.- Parameters:
path (str or path-like) – The saved model file.
- Returns:
HostForest
- property n_trees#
Number of trees in the model.
- property inference_engine#
‘sequential’ or ‘parallel_groves’. Read-only.
- Type:
The inference engine the file named
- model_sha256()[source]#
SHA-256 hex digest of the model arrays’ bytes, in save order.
Identifies the exact model used for a prediction.