Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Davis David Davisy

🎯
Focusing
View GitHub Profile
View load_hyperparameter_searches.py
# load your hyperparameter searches
study = joblib.load('optuna_searches/study.pkl')
View save_hyperparameter_searches.py
# save your hyperparameter searches
joblib.dump(study, 'optuna_searches/study.pkl')
View plot_optimization_history.py
optuna.visualization.plot_optimization_history(study)
View run_optimization_process.py
# pass the objective function to method optimize()
study.optimize(objective, n_trials=10)
View create_study_object.py
# create a study object
study = optuna.create_study(study_name="randomForest_optimization",
direction="maximize",
sampler=TPESampler())
View search_space_and_objective_function.py
# 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,
View objective_functon_optuna.py
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,
View imports_optuna.py
# import packages
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn import metrics
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
import joblib
import optuna
You can’t perform that action at this time.