Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Hyperparameter Optimization for Machine Learning Models.

Project description

SHERPA: A Python Hyperparameter Optimization Library

.. figure::
:figwidth: 100%
:align: right
:height: 150px
:alt: SHERPA logo

.. image::

.. image::

SHERPA is a Python library for hyperparameter tuning of machine learning models. It provides:

* hyperparameter optimization for machine learning researchers
* it can be used with any Python machine learning library such as Keras, Tensorflow, or Scikit-Learn
* a choice of hyperparameter optimization algorithms
* parallel computation that can be fitted to the user's needs
* a live dashboard for the exploratory analysis of results.

Install via ``pip install parameter-sherpa``. The documentation at provides tutorials on using the different optimization algorithms and installation instructions for parallel hyperparameter
optimizations. Take a look at the demo
video by clicking on the image below or read on to find out more.

.. image::

>From Keras to Sherpa in 30 seconds

This example will show how to adapt a minimal Keras script so it can
be used with SHERPA. As starting point we use the "getting started in 30 seconds"
tutorial from the Keras webpage.

We start out with this piece of Keras code:


from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(units=64, activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax'))

We want to tune the number of hidden units via Random Search. To do that, we
define one parameter of type `Discrete`.
We also use the `BayesianOptimization` algorithm with maximum number of trials 50.


import sherpa
parameters = [sherpa.Discrete('num_units', [50, 200])]
alg = sherpa.algorithms.BayesianOptimization(max_num_trials=50)

We use these objects to create a SHERPA Study:


study = sherpa.Study(parameters=parameters,

We obtain `trials` by iterating over the study. Each `trial` has a `parameter`
attribute that contains the ``num_units`` parameter value. We can use that value
to create our model.


for trial in study:
model = Sequential()
activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax'))
metrics=['accuracy']), y_train, epochs=5, batch_size=32,
callbacks=[study.keras_callback(trial, objective_name='val_loss')])

During training, objective values will be added to the SHERPA study via the
callback. At the end of training ``study.finalize`` completes this trial. This means
that no more observation will be added to this trial.

When the ``Study`` is created, SHERPA will display the dashboard address. If you
put the address into your browser you will see the dashboard as shown below. As a next step you
can take a look at this example of optimizing a Random Forest in

.. figure::
:alt: SHERPA Dashboard.

Installation from PyPi


pip install parameter-sherpa

Installation from GitHub

Clone from GitHub:


git clone
export PYTHONPATH=$PYTHONPATH:`pwd`/sherpa

Install dependencies:


pip install pandas
pip install numpy
pip install scipy
pip install scikit-learn
pip install flask
pip install enum34 # if on < Python 3.4

You can run an example to verify SHERPA is working:


cd sherpa/examples/

Note that to run hyperparameter optimizations in parallel with SHERPA requires
the installation of Mongo DB. Further instructions can be found in the
Parallel Installation section of the documentation.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for parameter-sherpa, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size parameter_sherpa-1.0.0-py2.py3-none-any.whl (547.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page