Skip to content

Instantly share code, notes, and snippets.

@Justus-coded
Last active December 5, 2020 17:01
Show Gist options
  • Save Justus-coded/210ae38a0a615be976f8aa2e23fa4243 to your computer and use it in GitHub Desktop.
Save Justus-coded/210ae38a0a615be976f8aa2e23fa4243 to your computer and use it in GitHub Desktop.
Hyperparameter tuning using Grid Search
#import libraries
from sklearn import datasets
from catboost import CatBoostClassifier
from sklearn.model_selection import GridSearchCV
# load data
cancer = datasets.load_breast_cancer()
# target
y = cancer.target
# features
X = cancer.data
#Instantiate CatBoostClassifier
cbc = CatBoostClassifier()
#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_)
#returns the best score
print(gscv.best_score_)
#returns the best parameters
print(gscv.best_params_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment