Created
December 5, 2020 17:13
-
-
Save Justus-coded/e27fe99062729f0acb8cc643bde4a80d to your computer and use it in GitHub Desktop.
Hyperparameter tuning using RandomizedSearchCV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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