Skip to content

Add optional feature type auto detection to Catboost and also auto sorting of ranking groups #28

Description

@thomasATbayer

Summary: CatBoost Feature Type Auto-Detection with Manual Configuration Override plus some additional fixes

This will also enable feature selection on embedding, text and categorial features when using the Mother Carboost with freature type detection for the feature selectors

This PR adds flexible feature type handling to CatBoost models by combining automatic dtype-based detection with explicit manual configuration through the Mother config system.

The callback logic was improved to automatically skip Optuna early stopping when hold-out validation or any cross-validation with fewer than 2 splits is used, preventing errors and ensuring correct behavior. This allows the use of hold out sets.

The default boostrap for catboost optimization using Optuna is now MVS, was not clear from the documentation if Bayesian or MVS, but generated some catboost models to check.

The catboost ranker can now handle non integer query groups i.e. dtype category and if the data is not sorted according to groups will be auto sorted.

🎯 What This Adds

Two complementary approaches for specifying feature types:

  1. Automatic Detection (opt-in via flags):

    • auto_class_categorical=True - Auto-detects columns with category dtype
    • auto_parse_text=True - Auto-detects object dtype columns containing strings
    • auto_parse_embedding=True - Auto-detects object dtype columns containing vectors (lists, arrays)
  2. Manual Configuration (via Mother config):

    • categorical_features: [] - Explicitly specify categorical feature column names
    • text_features: [] - Explicitly specify text feature column names
    • embedding_features: [] - Explicitly specify embedding feature column names
  3. Why 'category' dtype is required instead of 'object':

    • The ambiguity problem with object dtype (can be categorical strings, text, or vectors)
    • The design philosophy of being explicit and intentional
    • The practical benefit of better pandas and catboost performance

🔄 How Old and New Approaches Combine

Smart Precedence System:

  • Manual configuration ALWAYS takes precedence over auto-detection
  • Auto-detection only activates when:
    1. The feature type is NOT explicitly specified in config, AND
    2. The corresponding auto-detection flag is enabled, AND
    3. Input is a pandas DataFrame (auto-detection requires column names)

Cross-type exclusion:

  • Features manually specified in any type list are automatically excluded from auto-detection in other types
  • Prevents a single feature from appearing in multiple type lists

Example workflow:

# Config specifies some features manually
categorical_features: ["feature_A"]
text_features: ["feature_B"]

# At runtime with auto_parse_embedding=True:
# - "feature_A" used as categorical (from config)
# - "feature_B" used as text (from config)  
# - Embedding features auto-detected from remaining object dtype vector columns
# - "feature_A" and "feature_B" excluded from embedding auto-detection

🚀 Extension Points

Architecture improvements:

  1. Reusable detection utilities (mother/ml/models/utils.py):
    • detect_categorical_features() - Finds 'category' dtype columns
    • detect_text_features() - Finds object dtype string columns
    • detect_embedding_features() - Finds object dtype vector columns
    • Can be reused by future model implementations beyond CatBoost

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions