Skip to content

Instantly share code, notes, and snippets.

@shinichi-takayanagi
Created November 13, 2021 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinichi-takayanagi/57f041614e91011100aae55c0bfe8eca to your computer and use it in GitHub Desktop.
Save shinichi-takayanagi/57f041614e91011100aae55c0bfe8eca to your computer and use it in GitHub Desktop.
Classifier Comparison: GradientBoostingClassifier vs XGBClassifier vs LGBMClassifier vs CatBoostClassifier
from numpy import mean
from numpy import std
from sklearn.datasets import make_classification
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import RepeatedStratifiedKFold
# Models
from sklearn.ensemble import GradientBoostingClassifier
from xgboost import XGBClassifier
from lightgbm import LGBMClassifier
from catboost import CatBoostClassifier
# define dataset
X, y = make_classification(n_samples=3000, n_features=20, n_informative=15, n_redundant=5, random_state=1)
print(X[1:5,:])
# evaluate the model
classifiers = {
"XGBoost": XGBClassifier(),
"GradientBoostingClassifier": GradientBoostingClassifier(),
"LGBMClassifier": LGBMClassifier(),
"CatBoostClassifier": CatBoostClassifier()
}
cv = RepeatedStratifiedKFold(n_splits=5, n_repeats=3, random_state=1)
for name, model in classifiers.items():
n_scores = cross_val_score(model, X, y, scoring="roc_auc", cv=cv, n_jobs=-1, error_score='raise')
print(f"{name}\n{mean(n_scores)}, {std(n_scores)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment