Hyperopt

0.2.7 · deprecated · verified Thu Apr 09

Hyperopt is a Python library for distributed asynchronous hyperparameter optimization, enabling optimization over awkward search spaces including real-valued, discrete, and conditional dimensions. It uses Bayesian optimization algorithms like Tree of Parzen Estimators (TPE) and Random Search to efficiently find optimal hyperparameters for machine learning models. The current PyPI version is 0.2.7.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use Hyperopt to find the minimum of a simple mathematical function. It involves defining an objective function, specifying a search space using `hp` functions, creating a `Trials` object to log results, and finally calling `fmin` with a chosen algorithm (TPE in this case) and the maximum number of evaluations.

import numpy as np
from hyperopt import fmin, tpe, hp, STATUS_OK, Trials

# 1. Define the objective function to minimize
def objective(args):
    x, y = args
    return {'loss': x ** 2 + y ** 2, 'status': STATUS_OK}

# 2. Define the search space
space = [
    hp.uniform('x', -10, 10),
    hp.uniform('y', -10, 10)
]

# 3. Create a Trials object to store results
trials = Trials()

# 4. Run the optimization
best = fmin(objective, space, algo=tpe.suggest, max_evals=100, trials=trials)

print("Best parameters found:", best)
print("Best loss found:", trials.best_trial['result']['loss'])

view raw JSON →