Skip to content

Instantly share code, notes, and snippets.

@kusal1990
Created June 2, 2022 18:27
Show Gist options
  • Save kusal1990/cca361e1fbe6bd87487db617c5f0799f to your computer and use it in GitHub Desktop.
Save kusal1990/cca361e1fbe6bd87487db617c5f0799f to your computer and use it in GitHub Desktop.
# hyperparameter tuning the DecisionTree model
params ={'max_depth':[1, 5, 10, 50],'min_samples_split':[5, 10, 100, 500]}
# Create a custom (MCC) metric for evaluation of the model performance while
mcc = make_scorer(matthews_corrcoef, greater_is_better=True)
# Create an XGBoost classifier object with log-loss as the loss function to minimize
dt_clf = tree.DecisionTreeClassifier(random_state=42, class_weight='balanced')
# Perform stratified 5-fold cross validation
grid_clf = GridSearchCV(dt_clf, params, scoring=mcc, cv=5, return_train_score=True)
# Fit the model
grid_clf .fit(X_train, y_train)
print(f"Best CV score: {grid_clf.best_score_}")
@kusal1990
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment