Skip to content

Instantly share code, notes, and snippets.

@WillKoehrsen
Created July 2, 2018 15:19
Show Gist options
  • Save WillKoehrsen/19b8c836ee60cad8234020f78e58045b to your computer and use it in GitHub Desktop.
Save WillKoehrsen/19b8c836ee60cad8234020f78e58045b to your computer and use it in GitHub Desktop.
# Read in results and sort with best on top
results = pd.read_csv('gbm_trials.csv')
results.sort_values('loss', ascending = True, inplace = True)
# Extract the ideal number of estimators and hyperparameters
best_bayes_estimators = int(results.iloc[0, 4])
best_bayes_params = results.iloc[0, 1]
# Re-create the best model and train on the training data
best_bayes_model = lgb.LGBMClassifier(**best_bayes_params,
n_estimators=best_bayes_estimators, n_jobs = -1,
objective = 'binary', random_state = 50)
best_bayes_model.fit(features, labels)
# Evaluate on the testing data
preds = best_bayes_model.predict_proba(test_features)[:, 1]
from sklearn.metrics import roc_auc_score
score = roc_auc_score(test_labels, preds)
print('The best model scores {:.5f} AUC ROC on the test set.'.format(score))
print('This was achieved after {} search iterations'.format(results.iloc[0, 2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment