2
$\begingroup$

I know it's easy to do grid search for a simple Catboost model, such as in here: https://medium.com/aiplusoau/hyperparameter-tuning-a5fe69d2a6c7

by running something like

cbc = CatBoostRegressor()

#create the grid
grid = {'max_depth': [3,4,5],'n_estimators':[100, 200, 300]}

#Instantiate GridSearchCV
gscv = GridSearchCV (estimator = cbc, param_grid = grid, scoring 
='accuracy', cv = 5)

#fit the model
gscv.fit(X,y)

#returns the estimator with the best performance
print(gscv.best_estimator_)

Method like this did not have the input of categorical columns in the Catboost model.

But my question is how can I do grid search for categorical_cols specified?

For example, here is my code how I assign the categorical columns:

categorical_cols =  ['site_number','product_key', 'manufacturer_desc']


# initialize Pool
train_pool = Pool(X_train, 
                  y_train, 
                  cat_features=categorical_cols)
test_pool = Pool(X_test, 
                 cat_features=categorical_cols) 


# specify the training parameters 
model = CatBoostRegressor(iterations=150, 
                          learning_rate = 0.5,
                          depth=8,  
                          random_seed = 42
                          )
#train the model
model.fit(train_pool)

But this is the model without grid search. The question is how can I still do the grid search with the above categorical_cols specified. The train_pool and test_pool is already specified, not sure what's a best way.

Thanks!

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.