Hyperoptim
Hyperparameter Optimization Using Genetic Algorithm.
Installation
OS X , Windows & Linux:
pip install hyperoptim
Usage example
Use for find best hyperparameter
from hyperoptim import GASearch, Hparams
import tensorflow as tf
from tensorflow import keras
(img_train, label_train), (img_test, label_test) = keras.datasets.fashion_mnist.load_data()
# define hyperparameter space
ht = Hparams()
hp_units = ht.Int('units', min_value=32, max_value=512, step=32)
hp_learning_rate = ht.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])
hp_activation = ht.Choice('activation', values=['relu', 'sigmoid', 'tanh'])
# create the list of hyperparameter
params = [hp_units, hp_learning_rate, hp_activation]
# define model
params = [hp_units, hp_learning_rate, hp_activation]
def model_builder(params):
model = keras.Sequential()
model.add(keras.layers.Flatten(input_shape=(28, 28)))
# here params[0] refer to hp_units and params[2] refer to hp_activation
model.add(keras.layers.Dense(units=params[0], activation=params[2]))
model.add(keras.layers.Dense(10))
model.compile(optimizer=keras.optimizers.Adam(learning_rate=params[1]),
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
return model
# intialize the GASearch
tuner = GASearch(model_builder=model_builder, params=params, objective='val_accuracy', weights=(1.0,), max_epochs=10, directory='my_dir', project_name='intro_to_kt')
# run the search
tuner.search(img_train, label_train, epochs=2, validation_split=0.2)
# Get the optimal hyperparameters
best_hps=tuner.get_best_hyperparameters()[0]
# Build the model with the optimal hyperparameters and train it on the data for 50 epochs
model = tuner.build(best_hps)
history = model.fit(img_train, label_train, epochs=2, validation_split=0.2)
val_acc_per_epoch = history.history['val_accuracy']
best_epoch = val_acc_per_epoch.index(max(val_acc_per_epoch)) + 1
print('Best epoch: %d' % (best_epoch,))
eval_result = model.evaluate(img_test, label_test)
print("[test loss, test accuracy]:", eval_result)
Development setup
For local development setup
git clone https://github.com/deepak7376/hyperoptim
cd hyperoptim
pip install -r requirements.txt
Meta
Deepak Yadav
Distributed under the MIT license. See LICENSE for more information.
https://github.com/deepak7376/hypertune/blob/master/LICENSE
References
None
Metadata
Release files for hyperoptim 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hyperoptim-0.0.1.tar.gz | 4.4 kB | Without provenance | Details for hyperoptim-0.0.1.tar.gz |
Release files / hyperoptim-0.0.1.tar.gz
| Download URL | hyperoptim-0.0.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14dc4248b33d36448523d53d715e724f33d21a7fb397149e10fca4d36aa7b9f8
|
|
BLAKE2b-256 checksum How to use checksums |
02bd377dfda04800519b605c671a5b2eac27637ebeaaf467051235ca27853adf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.1
|
Security for hyperoptim 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.