Skip to content

predict

Apply the model to the given dataset.

Note

The model prediction results will be correct only if the X parameter with feature values contains all the features used in the model. For a polars DataFrame or LazyFrame, the features are matched by name: extra columns are ignored and the order of the columns does not matter (a LazyFrame collects only the columns the model needs). For other types, and for a model trained without feature names, the features must be in the same number and order as the columns provided during the training.

Method call format

predict(X, *, offset=None)

Parameters

X

Description

Feature values data.

Possible types

  • polars.DataFrame
  • polars.LazyFrame
  • numpy.ndarray of shape (object_count, feature_count)
  • other array-like data of the same shape

Default value

Required parameter

offset

Description

The link-scale offset to add to the raw score of each object, as passed to the offset parameter of fit. A string names a column of a polars X. If omitted, the objects are scored with a zero offset.

Possible types

  • numpy.ndarray of shape (object_count,)
  • polars.Series
  • list
  • string

Default value

None

Return value

A one-dimensional numpy.ndarray of shape (object_count,) with the prediction for each object, on the scale of the target.

For the poisson, gamma and tweedie objectives, the prediction is the rate per unit of exposure, not the total for the object: the expected total is predict(X) * exposure. An exposure column in X is ignored.

The values are float64. The model calculates in float32, and the wider type avoids accumulating rounding errors in downstream metrics.

Usage examples

rate = model.predict(test_data)
expected_claims = rate * test_data["Exposure"].to_numpy()