In this article
A categorical integer code is an identity under a fitted mapping; its sign and declaration can change how the library interprets it.
Declare the categorical role
An integer-valued column can be interpreted as a numerical quantity or a categorical identity depending on configuration. The LightGBM parameter reference defines categorical feature declarations. Preserve that role with the feature schema rather than assuming every small integer column is categorical. Native category splits and numerical threshold splits express different relationships, even when they consume an array with identical values and dtype.
Preserve valid integer identities
The advanced topics guide describes casting categorical values to a bounded integer representation and recommends compact nonnegative codes. Negative categorical values are treated as missing, not as ordinary additional classes. An external encoder using a negative sentinel for a meaningful other category therefore needs deliberate adaptation. A library accepting the array does not prove that the sentinel retained the semantic role assigned by upstream preprocessing.
Keep prediction mappings aligned with training
The guide describes category alignment for supported pandas categorical inputs and treatment of previously unseen categories as missing at prediction. That contract differs from independently fitting a new encoder on a prediction table. The Python estimator reference explains categorical configuration and feature naming. When using raw numerical arrays instead, preserve the original mapping explicitly so the same integer does not represent different categories in different batches.
Separate identity from category distance
The integer ordering is an encoding convention, not evidence that one nominal category lies numerically between two others. The TabPFN schema guide provides a related representation comparison. If a column is intentionally treated as numerical, document that different modeling decision. Likewise, a high-cardinality field needs a measured task-specific choice rather than an assumption that an arbitrary hash range creates useful ordinal structure for the tree learner.
Validate missing and unseen cases explicitly
Use known categories, an unseen category, a negative sentinel and a reordered input schema as reviewed fixtures. Verify the supported pandas path separately from any external array encoder, and compare the intended reference predictions. The entity-group guide supplies related identity reasoning. A reliable integration preserves declaration, code meaning and missingness through fit and predict, then evaluates quality; successful conversion to integers alone does not establish that the model saw the intended category for each application row.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.