Skip to content

Instantly share code, notes, and snippets.

@Justus-coded
Created December 5, 2020 17:13
Show Gist options
  • Save Justus-coded/e27fe99062729f0acb8cc643bde4a80d to your computer and use it in GitHub Desktop.
Save Justus-coded/e27fe99062729f0acb8cc643bde4a80d to your computer and use it in GitHub Desktop.
Hyperparameter tuning using RandomizedSearchCV
#Import libraries
import numpy as np
from scipy.stats import randint
from catboost import CatBoostClassifier
from sklearn.model_selection import RandomizedSearchCV
# load data
cancer = datasets.load_breast_cancer()
# target
y = cancer.target
# features
X = cancer.data
#Instantiate CatBoostClassifier
cbc = CatBoostClassifier()
# Creating the hyperparameter grid
param_dist = { "learning_rate": np.linspace(0,0.2,5)
"max_depth": randint(3, 10)}
#Instantiate RandomSearchCV object
rscv = RandomizedSearchCV(cbc , param_dist, scoring='accuracy', cv =5)
#Fit the model
rscv.fit(X,y)
# Print the tuned parameters and score
print(rscv.best_params_)
print(rscv.best_score_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment