You can download this code by clicking the button below.
This code is now available for download.
This function uses the CatBoost library to train a classification model. It takes a feature matrix X and a label vector y as input, splits the dataset into training and validation sets, and then trains a CatBoost classifier.
Technology Stack : CatBoost, scikit-learn
Code Type : Function
Code Difficulty : Intermediate
import catboost as cb
from sklearn.model_selection import train_test_split
def train_catboost_model(X, y):
# Split the data into training and validation sets
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)
# Create a CatBoost model
model = cb.CatBoostClassifier()
# Train the model
model.fit(X_train, y_train, eval_set=(X_val, y_val), verbose=10)
return model