Skip to content

cell_indices

Return the rating-table cell every object falls in, for every deployed dense table.

The cells follow the rules described in How an object finds its cell: numeric values are compared in float32, cell 0 holds missing values, and a value equal to a border lands in the lower cell.

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

cell_indices(X)

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

Return value

A dictionary with one entry per dense table, keyed by the tuple of the table's feature names (the same keys as the terms of ContributionMatrix and the feature_names of tables). Each value is a numpy.uint32 array of shape (object_count, order) with the object's cell on each axis of the table, in the table's axis order. Effects stored in factored form have no cells and are not listed.

For an exported table, values[numpy.ravel_multi_index(tuple(cells.T), shape)] is the contribution of the table to each object.

ValueError is raised for a multiclassification model (which has one set of tables per class) and for a model saved by t-boost 0.6 or earlier.

Usage examples

import json
import numpy as np

cells = model.cell_indices(test_data)
tables = {tuple(t["feature_names"]): t for t in json.loads(model.tables(train_data))["tables"]}
table = tables[("DriverAge",)]
values = np.asarray(table["values"])[np.ravel_multi_index(tuple(cells[("DriverAge",)].T), table["shape"])]