Skip to main content

A custom library for hyperparameter optimization using Grid Search, Random Search, and Bayesian Optimization.

Project description

Hypertune

Hypertune is a Python library designed to simplify hyperparameter optimization for machine learning models. It supports different search strategies, including Grid Search, Random Search, and Bayesian Optimization, to find the best hyperparameters for your model and improve its performance.

Features

  • Grid Search: Exhaustively searches through a manually specified grid of hyperparameters.
  • Random Search: Randomly samples hyperparameter combinations to find optimal settings.
  • Bayesian Optimization: Uses probabilistic models to predict the best hyperparameters and minimize the number of trials needed.

Installation

You can install Hypertune using pip from PyPI:

pip install hypertune

Usage

Here’s how to use Hypertune with a machine learning model:

1. Import the library

from hypertune import Hypertune
from hypertune.grid_search import GridSearch
from hypertune.random_search import RandomSearch
from hypertune.bayesian_search import BayesianSearch

2. Define the model and parameters

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris

# Load a dataset
X, y = load_iris(return_X_y=True)

# Define the model
model = RandomForestClassifier()

# Define hyperparameter search space for GridSearch
param_grid = {
    'n_estimators': [50, 100, 200],
    'max_depth': [None, 10, 20],
    'min_samples_split': [2, 5, 10]
}

3. Run Grid Search

# Create the GridSearch object
grid_search = GridSearch(model, param_grid)

# Fit the model and find the best parameters
grid_search.fit(X, y)

# Get the best hyperparameters
print("Best Hyperparameters:", grid_search.best_params_)

4. Run Random Search

# Define the random search space
param_dist = {
    'n_estimators': [50, 100, 200, 300],
    'max_depth': [None, 10, 20, 30],
    'min_samples_split': [2, 5, 10, 15]
}

# Create the RandomSearch object
random_search = RandomSearch(model, param_dist)

# Fit the model and find the best parameters
random_search.fit(X, y)

# Get the best hyperparameters
print("Best Hyperparameters:", random_search.best_params_)

5. Run Bayesian Optimization

# Define the hyperparameter search space for Bayesian Optimization
param_space = {
    'n_estimators': (50, 200),
    'max_depth': (1, 30),
    'min_samples_split': (2, 15)
}

# Create the BayesianSearch object
bayesian_search = BayesianSearch(model, param_space)

# Fit the model and find the best parameters
bayesian_search.fit(X, y)

# Get the best hyperparameters
print("Best Hyperparameters:", bayesian_search.best_params_)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

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

Source Distribution

hypertune_param-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypertune_param-0.1.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file hypertune_param-0.1.1.tar.gz.

File metadata

  • Download URL: hypertune_param-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for hypertune_param-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5a9814dbafa2816b7cf409860c435cbdc87a43900a65a19f6f636ab035a9b362
MD5 01f6cd9f3d3d55dfa69ae2ac1687f6ea
BLAKE2b-256 df74ac76c45dd8f3e78e051785c42bd6eadd624f0c0ceabc717e64845b5650ac

See more details on using hashes here.

File details

Details for the file hypertune_param-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hypertune_param-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8b7f5e8eea8ed403cfb3e042c72fb37845180d5e6b0992d61c5187b1dda910a
MD5 c7489a5750fbfcfdbfc02a3176705ef1
BLAKE2b-256 5e46f17e920216b8b1516eb2904de0ca6a5ec292e16d9127a9dd727b076197c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page