Skip to content

Instantly share code, notes, and snippets.

@Justus-coded
Last active December 5, 2020 16:43
Show Gist options
  • Save Justus-coded/3de5de9b1ec89badead0666a74bd1f52 to your computer and use it in GitHub Desktop.
Save Justus-coded/3de5de9b1ec89badead0666a74bd1f52 to your computer and use it in GitHub Desktop.
Hyperparameter tuning of Machine learning models using manual tuning
#import libraries
from sklearn import datasets
from catboost import CatBoostClassifier
from sklearn.model_selection import cross_val_score
# load data
cancer = datasets.load_breast_cancer()
# target
y = cancer.target
# features
X = cancer.data
#Instantiate CatBoostClassifier, using a maximum depth of 3
cbc = CatBoostClassifier(max_depth=3)
# 5 folds, scored on accuracy
cvs = cross_val_score(cbc, X, y, cv=5, scoring='accuracy')
#Mean value of cross validation score
print (f 'The mean value of cross val score is {cvs.mean()}') #mean = 0.96
print("======="*5)
#Instantiate CatBoostClassifier, using a maximum depth of 5
cbc1 = CatBoostClassifier(max_depth=5)
# 5 folds, scored on accuracy
cvs1 = cross_val_score(cbc1, X, y, cv=5, scoring='accuracy')
#Mean value of cross validation score
print (f 'The mean value of cross val score is {cvs1.mean()}') #mean = 0.97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment