Git Product home page Git Product logo

confopt's Introduction

ConfOpt

License arXiv

ConfOpt is an inferential hyperparameter optimization package designed to speed up model hyperparameter tuning.

The package currently implements Adaptive Conformal Hyperparameter Optimization (ACHO), as detailed in the original paper.

Installation

You can install ConfOpt from PyPI using pip:

pip install confopt

Getting Started

As an example, we'll tune a Random Forest model with data from a regression task.

Start by setting up your training and validation data:

from sklearn.datasets import fetch_california_housing

X, y = fetch_california_housing(return_X_y=True)
split_idx = int(len(X) * 0.5)
X_train, y_train = X[:split_idx, :], y[:split_idx]
X_val, y_val = X[split_idx:, :], y[split_idx:]

Then import the Random Forest model to tune and define a search space for its parameters (must be a dictionary mapping the model's parameter names to possible values of that parameter to search):

from sklearn.ensemble import RandomForestRegressor

parameter_search_space = {
    "n_estimators": [10, 30, 50, 100, 150, 200, 300, 400],
    "min_samples_split": [0.005, 0.01, 0.1, 0.2, 0.3],
    "min_samples_leaf": [0.005, 0.01, 0.1, 0.2, 0.3],
    "max_features": [None, 0.8, 0.9, 1],
}

Now import the ConformalSearcher class and initialize it with:

  • The model to tune.
  • The raw X and y data.
  • The parameter search space.
  • An extra variable clarifying whether this is a regression or classification problem.

Hyperparameter tuning can be kicked off with the search method and a specification of how long the tuning should run for (in seconds):

from confopt.tuning import ConformalSearcher

searcher = ConformalSearcher(
    model=RandomForestRegressor(),
    X_train=X_train,
    y_train=y_train,
    X_val=X_val,
    y_val=y_val,
    search_space=parameter_search_space,
    prediction_type="regression",
)

searcher.search(
    runtime_budget=120  # How many seconds to run the search for
)

Once done, you can retrieve the best parameters obtained during tuning using:

searcher.get_best_params()

Or obtain an already initialized model with:

searcher.get_best_model()

More information on specific parameters and overrides not mentioned in this walk-through can be found in the docstrings or in the examples folder of the main repository.

confopt's People

Contributors

rick12000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

valeman indykpol

confopt's Issues

CatBoost Classifier

Hi Rick,

I'm trying to use your code with the CatBoost classifier but got the following error message:

ValueError: Unable to auto-allocate evaluation metric for classifier prediction type.

What do I do? Below is my code:

parameter_search_space = {
'iterations_values': [100, 200, 300],
'depth_values': [6, 7, 8, 9],
'learning_rate_values': [0.1, 0.05, 0.01],
}

from confopt.tuning import ConformalSearcher

searcher = ConformalSearcher(
model=CatBoostClassifier(),
X_train=X_train,
y_train=y_train,
X_val=X_Cal,
y_val=y_cal,
search_space=parameter_search_space,
prediction_type="classifier",
)

searcher.search(
runtime_budget=120 # How many seconds to run the search for
)

Attached is the error screenshot.

Screenshot 2024-02-11 135941

Cheers
Kush

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.