mojolearn.HostGBDT#
- class mojolearn.HostGBDT(*, loss, text, n_features_in, approx_dim, n_classes=None, numeric_mode=None, bias=None, estimator='GradientBoosting')[source]#
Bases:
objectCPU inference for a saved gradient-boosting model.
Loads a file written by
GradientBoosting.save(alsoOrderedRMSEandExperimentalTwoLevelFeatureFreqmodels) and predicts on the CPU, with no GPU needed.predictreturns whatGradientBoosting.predictreturns for the same file. Models with categorical (CTR) columns are supported; a model that uses CTR table types with no prediction-time formula (Buckets, BinarizedTargetMeanValue, FloatTargetMeanValue) is refused at load.Build one with from_file(). The constructor takes the archive’s fields directly and refuses a file whose fields disagree with its model text as corrupt.
- Parameters:
loss (str) – The loss the model was fitted with.
text (str) – The model text (
GradientBoosting.model_).n_features_in (int)
approx_dim (int) – Number of raw outputs per row.
n_classes (int or None, default None)
numeric_mode (str or None, default None) – The numeric mode recorded with the model.
bias (float or None, default None)
estimator (str, default ‘GradientBoosting’) – The class that saved the model.
- Variables:
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).random((1000, 8), dtype=np.float32) >>> y = (X[:, 0] > 0.5).astype(np.float32) >>> mojolearn.GradientBoosting(loss="Logloss", n_estimators=50).fit(X, y).save("gb.npz") >>> host = mojolearn.HostGBDT.from_file("gb.npz") >>> proba = host.predict_proba(X)
- __init__(*, loss, text, n_features_in, approx_dim, n_classes=None, numeric_mode=None, bias=None, estimator='GradientBoosting')[source]#
Methods
from_file(path)Load a model from a file written by
GradientBoosting.save.Return the SHA-256 hex digest of the model text (UTF-8).
predict(X)Return raw float32 scores, as
GradientBoosting.predictdoes.Return float64 class probabilities
[1 - p, p]forLoglossandCrossEntropymodels.Attributes
estimatorName of the prediction engine,
'sequential'.Number of trees in the model.
the input columns, or more for a CTR model
- n_model_columns_#
the input columns, or more for a CTR model
- Type:
model columns
- classmethod from_file(path)[source]#
Load a model from a file written by
GradientBoosting.save.- Parameters:
path (str or path-like)
- Returns:
HostGBDT
- Raises:
ValueError – If the file was saved by another class or is corrupt.
- property n_trees#
Number of trees in the model.
- property inference_engine#
Name of the prediction engine,
'sequential'.
- model_sha256()[source]#
Return the SHA-256 hex digest of the model text (UTF-8).
It equals the digest of the archive’s
modelmember.
- predict(X)[source]#
Return raw float32 scores, as
GradientBoosting.predictdoes.- Parameters:
X (array-like of shape (n_samples, n_features))
- Returns:
mojolearn.Array – Shape
(n_samples,)for a single-output loss, otherwise(n_samples, approx_dim).
- predict_proba(X)[source]#
Return float64 class probabilities
[1 - p, p]forLoglossandCrossEntropymodels.Matches
GradientBoosting.predict_probafor these losses.MultiClassandMultiClassOneVsAllmodels raiseNotImplementedError; any other loss raisesValueError.- Parameters:
X (array-like of shape (n_samples, n_features))
- Returns:
mojolearn.Array – Shape
(n_samples, 2).