diff --git a/README.md b/README.md index fe6651e9..edcc0eec 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,49 @@ prediction = Optimizer.predict(X_test) score = Optimizer.score(X_test, y_test) ``` +Example with a feedforward neural network in keras (experimental): +```python +from sklearn.datasets import load_breast_cancer +from sklearn.model_selection import train_test_split + +from hyperactive import ParticleSwarm_Optimizer + +breast_cancer_data = load_breast_cancer() +X = breast_cancer_data.data +y = breast_cancer_data.target + +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) + +# this defines the structure of the model and the search space in each layer +search_config = { + "keras.compile.0": {"loss": ["binary_crossentropy"], "optimizer": ["adam"]}, + "keras.fit.0": {"epochs": [5], "batch_size": [100]}, + "keras.layers.Dense.1": { + "units": range(5, 15), + "activation": ["relu"], + "kernel_initializer": ["uniform"], + }, + "keras.layers.Dense.2": { + "units": range(5, 15), + "activation": ["relu"], + "kernel_initializer": ["uniform"], + }, + "keras.layers.Dense.3": {"units": [1], "activation": ["sigmoid"]}, +} +Optimizer = ParticleSwarm_Optimizer(search_config, 3, cv=1) + +# search best hyperparameter for given data +Optimizer.fit(X_train, y_train) + +# predict from test data +prediction = Optimizer.predict(X_test) + +# calculate accuracy score +score = Optimizer.score(X_test, y_test) +``` + + + ## Hyperactive API diff --git a/hyperactive/__init__.py b/hyperactive/__init__.py index ffec9afc..dc0e8990 100644 --- a/hyperactive/__init__.py +++ b/hyperactive/__init__.py @@ -6,7 +6,7 @@ from .simulated_annealing import SimulatedAnnealing_Optimizer from .particle_swarm_optimization import ParticleSwarm_Optimizer -__version__ = "0.1.3" +__version__ = "0.1.4" __license__ = "MIT" __all__ = [ diff --git a/setup.py b/setup.py index 84f0b07d..475f2b46 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="hyperactive", - version="0.1.3", + version="0.1.4", author="Simon Blanke", author_email="simon.blanke@yahoo.com", license="MIT",