Skip to content
Quantoros

How can a reusable ColumnTransformer select all numeric columns without hard-coding their names?

Classic MLLevel: IntermediateDtype-based column selection

How can a reusable ColumnTransformer select all numeric columns without hard-coding their names?

Hints
  • Selection can be a callable.
  • Storage dtype is not semantic type.

Answer

Use a column selector based on dtype, such as make_column_selector(dtype_include=np.number). Still validate the input schema: an identifier stored as an integer is not necessarily a useful numeric measurement.

Source and licence: scikit-learn 1.7.2 — compose · BSD-3-Clause · answer: Quantoros editorial

Related questions