This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
optuna.visualization.plot_optimization_history(study) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(study.best_value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(study.best_params) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pass the objective function to method optimize() | |
study.optimize(objective, n_trials=10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a study object | |
study = optuna.create_study(study_name="randomForest_optimization", | |
direction="maximize", | |
sampler=TPESampler()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# plot convergence | |
from skopt.plots import plot_convergence | |
plot_convergence(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# summarizing finding: | |
print('Best Accuracy: %.3f' % (result.fun)) | |
print('Best Parameters: %s' % (result.x)) |