Skip to content

Instantly share code, notes, and snippets.

@Davisy
Created October 4, 2020 13:37
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/50723578f3b733cb5abf404e4a666db8 to your computer and use it in GitHub Desktop.
Save Davisy/50723578f3b733cb5abf404e4a666db8 to your computer and use it in GitHub Desktop.
# define the search space and the objecive function
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 = 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