Training CatBoost Regression Model with Python

  • Share this:

Code introduction


This function uses the CatBoost library to train a regression model. It takes training data X_train and labels y_train as input, and returns the trained model.


Technology Stack : CatBoost library, regression model, tree-based model

Code Type : Machine learning

Code Difficulty : Intermediate


                
                    
def train_catboost_model(X_train, y_train):
    from catboost import CatBoostRegressor

    # Initialize the CatBoost model
    model = CatBoostRegressor(
        depth=6,  # Maximum depth of the tree
        learning_rate=0.1,  # Learning rate
        boosting_type='gbdt',  # Type of the boosting
        subsample=0.8,  # Subsample ratio
        colsample_bynode=0.8  # Subsample ratio based on the number of leaves
    )

    # Train the model
    model.fit(X_train, y_train)

    return model