How to find optimal parameters for CatBoost using GridSearchCV for Regression?
1

How to find optimal parameters for CatBoost using GridSearchCV for Regression?

This recipe helps you find optimal parameters for CatBoost using GridSearchCV for Regression
In [1]:
def Snippet_199():
    print()
    print(format('How to find optimal parameters for CatBoost using GridSearchCV for Regression','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    from sklearn import datasets
    from sklearn.model_selection import train_test_split
    from sklearn.model_selection import GridSearchCV
    from catboost import CatBoostRegressor

    # load the iris datasets
    dataset = datasets.load_boston()
    X = dataset.data; y = dataset.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)

    model = CatBoostRegressor()
    parameters = {'depth'         : [6,8,10],
                  'learning_rate' : [0.01, 0.05, 0.1],
                  'iterations'    : [30, 50, 100]
                 }
    grid = GridSearchCV(estimator=model, param_grid = parameters, cv = 2, n_jobs=-1)
    grid.fit(X_train, y_train)

    # Results from Grid Search
    print("\n========================================================")
    print(" Results from Grid Search " )
    print("========================================================")
    print("\n The best estimator across ALL searched params:\n",
          grid.best_estimator_)
    print("\n The best score across ALL searched params:\n",
          grid.best_score_)
    print("\n The best parameters across ALL searched params:\n",
          grid.best_params_)
    print("\n ========================================================")

Snippet_199()
**How to find optimal parameters for CatBoost using GridSearchCV for Regression***
/Users/nilimesh/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_search.py:841: DeprecationWarning: The default of the `iid` parameter will change from True to False in version 0.22 and will be removed in 0.24. This will change numeric results when test-set sizes are unequal.
  DeprecationWarning)
0:	learn: 24.3387613	total: 82.8ms	remaining: 2.4s
1:	learn: 24.1574633	total: 109ms	remaining: 1.53s
2:	learn: 23.9656719	total: 136ms	remaining: 1.23s
3:	learn: 23.7609700	total: 137ms	remaining: 894ms
4:	learn: 23.5788095	total: 164ms	remaining: 820ms
5:	learn: 23.3981448	total: 194ms	remaining: 776ms
6:	learn: 23.2204106	total: 221ms	remaining: 725ms
7:	learn: 23.0637082	total: 248ms	remaining: 683ms
8:	learn: 22.8991486	total: 275ms	remaining: 642ms
9:	learn: 22.7361343	total: 304ms	remaining: 609ms
10:	learn: 22.5820524	total: 332ms	remaining: 573ms
11:	learn: 22.4015054	total: 339ms	remaining: 509ms
12:	learn: 22.2254804	total: 365ms	remaining: 478ms
13:	learn: 22.0342073	total: 367ms	remaining: 419ms
14:	learn: 21.8495471	total: 368ms	remaining: 368ms
15:	learn: 21.6805878	total: 380ms	remaining: 333ms
16:	learn: 21.5233731	total: 407ms	remaining: 311ms
17:	learn: 21.3576118	total: 420ms	remaining: 280ms
18:	learn: 21.1949842	total: 445ms	remaining: 258ms
19:	learn: 21.0149778	total: 446ms	remaining: 223ms
20:	learn: 20.8692226	total: 473ms	remaining: 203ms
21:	learn: 20.7145938	total: 500ms	remaining: 182ms
22:	learn: 20.5647041	total: 531ms	remaining: 162ms
23:	learn: 20.4190385	total: 559ms	remaining: 140ms
24:	learn: 20.2797164	total: 586ms	remaining: 117ms
25:	learn: 20.1265513	total: 594ms	remaining: 91.4ms
26:	learn: 19.9603994	total: 620ms	remaining: 68.9ms
27:	learn: 19.8206477	total: 647ms	remaining: 46.2ms
28:	learn: 19.6781954	total: 674ms	remaining: 23.2ms
29:	learn: 19.5353669	total: 701ms	remaining: 0us

========================================================
 Results from Grid Search
========================================================

 The best estimator across ALL searched params:
 <catboost.core.CatBoostRegressor object at 0x1a2302af60>

 The best score across ALL searched params:
 20.27497626782402

 The best parameters across ALL searched params:
 {'depth': 10, 'iterations': 30, 'learning_rate': 0.01}

 ========================================================