Python Library

You can use our Python API Client to call API endpoints.

Our Python API Client is available via pip, with source code on Github:

pip install sigopt

Sign up for an account at https://sigopt.com. In order to use the API, you’ll need your SIGOPT_API_TOKEN from your user dashboard. Then, use your client token to instantiate a SigOpt Connection object:

# Pass your API token directly, overriding any environment variables
from sigopt import Connection
conn = Connection(client_token=SIGOPT_API_TOKEN)

Run Some Code

Now, you can run SigOpt's Optimization Loop.

First, setup the experiment:

# Run `pip install sigopt` to download the python API client
from sigopt import Connection
from sigopt.examples import franke_function

conn = Connection(client_token=SIGOPT_API_TOKEN)

experiment = conn.experiments().create(
    name='Franke Optimization (Python)',
    parameters=[
        dict(name='x', type='double', bounds=dict(min=0.0, max=1.0)),
        dict(name='y', type='double', bounds=dict(min=0.0, max=1.0)),
    ],
)
print("Created experiment: https://sigopt.com/experiment/" + experiment.id)

Then, run the optimization loop itself:

# Evaluate your model with the suggested parameter assignments
# Franke function - http://www.sfu.ca/~ssurjano/franke2d.html
def evaluate_model(assignments):
    return franke_function(assignments['x'], assignments['y'])

# Run the Optimization Loop between 10x - 20x the number of parameters
for _ in range(30):
    suggestion = conn.experiments(experiment.id).suggestions().create()
    value = evaluate_model(suggestion.assignments)
    conn.experiments(experiment.id).observations().create(
        suggestion=suggestion.id,
        value=value,
    )

Run More Code: Tune a Random Forest

Learn how to Tune a Random Forest using SigOpt's Python API Client. This simple example uses an open source machine learning library and can be extended to tune the hyperparameters of any machine learning model.

More Examples

To see more examples of how to use Sigopt and Python to tune machine learning models and more, check out our Machine Learning Templates page or clone our Github examples repository:

git clone https://github.com/sigopt/sigopt-examples.git

Objects

The SigOpt Python API Client returns Python objects. Here is an example where we fetch an experiment and print the name:

experiment = conn.experiments(experiment_id).fetch()
print experiment.name

You can also refer to our complete API Object Reference.

Endpoints

Please refer to our complete API Endpoint Reference. Each page has a tab where you can view how to construct the endpoint call in Python. You can refer to the above section on objects for more information about the return type of the Python API Client calls.

Proxies

If you are connecting to SigOpt behind a proxy, you may need to configure your client appropriately.

conn.set_proxies({
  'http': 'http://10.10.1.10:3128',
  'https': 'http://user:[email protected]:1080',
})

See the documentation for the requests module for more information.