mojolearn.HostGBDT#

class mojolearn.HostGBDT(*, loss, text, n_features_in, approx_dim, n_classes=None, numeric_mode=None, bias=None, estimator='GradientBoosting')[source]#

Bases: object

CPU inference for a saved gradient-boosting model.

Loads a file written by GradientBoosting.save (also OrderedRMSE and ExperimentalTwoLevelFeatureFreq models) and predicts on the CPU, with no GPU needed. predict returns what GradientBoosting.predict returns 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:
  • n_features_in_ (int)

  • approx_dim_ (int)

  • bias_ (float)

  • n_classes_ (int or None)

  • model_ (str)

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.

model_sha256()

Return the SHA-256 hex digest of the model text (UTF-8).

predict(X)

Return raw float32 scores, as GradientBoosting.predict does.

predict_proba(X)

Return float64 class probabilities [1 - p, p] for Logloss and CrossEntropy models.

Attributes

estimator

inference_engine

Name of the prediction engine, 'sequential'.

n_trees

Number of trees in the model.

n_model_columns_

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 model member.

predict(X)[source]#

Return raw float32 scores, as GradientBoosting.predict does.

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] for Logloss and CrossEntropy models.

Matches GradientBoosting.predict_proba for these losses. MultiClass and MultiClassOneVsAll models raise NotImplementedError; any other loss raises ValueError.

Parameters:

X (array-like of shape (n_samples, n_features))

Returns:

mojolearn.Array – Shape (n_samples, 2).