Skip to content
Quantoros

A pandas column contains category labels but XGBoost rejects the input. What two data/model contracts should you…

Classic MLLevel: IntermediateXGBoost · Categorical data

A pandas column contains category labels but XGBoost rejects the input. What two data/model contracts should you inspect?

Hints
  • Values and dtype are not the same contract.
  • The estimator must also opt into categorical handling.

Answer

Verify that the column has categorical dtype, not merely object strings, and that categorical support is enabled with a supported tree method such as hist. Encoding and feature order must remain consistent at inference.

Source and licence: XGBoost · Categorical data · Apache-2.0 · answer: Quantoros editorial

Related questions