Skip to content

Instantly share code, notes, and snippets.

@Davisy
Created October 3, 2020 14:14
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 Davisy/13d1eff95ab08f58bb5f99bd57c4848c to your computer and use it in GitHub Desktop.
Save Davisy/13d1eff95ab08f58bb5f99bd57c4848c to your computer and use it in GitHub Desktop.
def objective(trial):
# Define the search space
criterions = trial.suggest_categorical('criterion', ['gini', 'entropy'])
max_depths = trial.suggest_int('max_depth', 1, 9, 1)
n_estimators = trial.suggest_int('n_estimators', 100, 1000, 100)
clf = sklearn.ensemble.RandomForestClassifier(n_estimators=n_estimators,
criterion=criterions,
max_depth=max_depths,
n_jobs=-1)
score = cross_val_score(clf, X_scaled, y, scoring="accuracy").mean()
return score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment