willkoehrsen / hyperparameter-optimization Goto Github PK
View Code? Open in Web Editor NEWImplementation of Bayesian Hyperparameter Optimization of Machine Learning Algorithms
Implementation of Bayesian Hyperparameter Optimization of Machine Learning Algorithms
Hi,
I am following your implementation of hyper-parameter optimization of GBR (in my case). I am getting error when I define a space
with nested data structure.
space = {
'boosting_type': hp.choice('boosting_type',
[{'boosting_type': 'gbdt', 'subsample': hp.uniform('gbdt_subsample', 0.5, 1)},
{'boosting_type': 'dart', 'subsample': hp.uniform('dart_subsample', 0.5, 1)},
{'boosting_type': 'goss', 'subsample': 1.0}]),
'num_leaves': hp.quniform('num_leaves', 30, 150, 1),
'learning_rate': hp.loguniform('learning_rate', np.log(0.01), np.log(0.2)),
'subsample_for_bin': hp.quniform('subsample_for_bin', 20000, 300000, 20000),
'min_child_samples': hp.quniform('min_child_samples', 20, 500, 5),
'reg_alpha': hp.uniform('reg_alpha', 0.0, 1.0),
'reg_lambda': hp.uniform('reg_lambda', 0.0, 1.0),
'colsample_bytree': hp.uniform('colsample_by_tree', 0.6, 1.0),
'objective': ['regression']
}
When I run
best = fmin(fn=objective, space= space, algo=tpe_algorithm, max_evals=MAX_EVAL, trials=bayes_trials, rstate=np.random.RandomState(50))
I am getting the following error: (I am pasting only the final error comments rather than the entire Trace which is rather long).
----> 5 best = fmin(fn=objective, space= space, algo=tpe_algorithm, max_evals=MAX_EVAL, trials=bayes_trials, rstate=np.random.RandomState(50))
...
...
TypeError: Unknown type of parameter:boosting_type, got:dict
Any advice will be of value to me.
Thanks
Whats the article you were referring to here - https://github.com/WillKoehrsen/hyperparameter-optimization/blob/master/Introduction%20to%20Bayesian%20Optimization%20with%20Hyperopt.ipynb?short_path=7f98da9#L51
Hello!
Thank you for the great guide and such a cool tool.
I am a little confused about how to create the params dictionary. I.e. do I just initialize the param values once by calling sample() e.g. in the example below i have called the sample() function within the namespace of the objective function. I assume then that fmin() will deal with subsequent assignments for each param... or am I thinking about this wrong?
Code:
def objective(params = sample(space)):
"""Objective function for AE Hyperparameter Optimization"""
# Keep track of evals
global ITERATION
ITERATION += 1
#generate parameters
# Make sure parameters that need to be integers are integers
for parameter_name in ['batch_size']:
params[parameter_name] = int(params[parameter_name])
start = timer()
# run AE with pre-defined k-fold reps
out, autoencoder, encoder, decoder = functionalModel(data=train_ctr.X, batch_size=params['batch_size'], epochs=100, dr=params['dropout'], reg=params['regularization'], lr=params['learning_rate'], optimizer='rmsprop')
run_time = timer() - start
# Extract the best score (MSE)
best_score = best_loss = out.history['loss'][-1]
# Loss must be minimized
loss = best_score
# Write to the csv file ('a' means append)
of_connection = open(out_file, 'a')
writer = csv.writer(of_connection)
writer.writerow([loss, params, ITERATION, run_time])
# Dictionary with information for evaluation
return {'loss': loss, 'params': params, 'iteration': ITERATION,
'train_time': run_time, 'status': STATUS_OK}
#run fmin
from hyperopt import fmin
# Global variable
global ITERATION
#initialize iteration to 0
ITERATION = 0
#max number of runs of algorithm
MAX_EVALS = 5
# Run optimization
best = fmin(fn = objective, space = space, algo = tpe.suggest,
max_evals = MAX_EVALS, trials = bayes_trials, rstate = np.random.RandomState(50))
I ask this before running, as I anticipate long run times, and your response may come back before my own troubleshooting.
Thanks!
I keep getting the following error from Lightgbm module. Have you ran this code recently? Looks like something is deprecated.
LightGBMError: Cannot change bin_construct_sample_cnt after constructed Dataset handle.
[LightGBM] [Fatal] Cannot change bin_construct_sample_cnt after constructed Dataset handle.
Hi!
I wonder if I can get the same result when I use this library several times(object function,bounds are same)? Because the reproducibility is import for paper.
Thank you for this helpful notebook. Can you explain why you return the best cv scores in the objective function? Isn't that an overly optimistic (upward bias) measure of performance?
I believe the results of the n_fold cross validations should be averaged and returned as the score/loss. Am I missing something?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.