Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Sklearn-Optuna

Python Version License PyPI Version Conda Version codecov

What is Sklearn-Optuna?

Sklearn-Optuna provides OptunaSearchCV, a drop-in replacement for Scikit-Learn's GridSearchCV and RandomizedSearchCV that uses Optuna for hyperparameter optimization. It extends BaseSearchCV so that fit(), score(), best_params_, cv_results_, and all other Scikit-Learn search attributes work exactly as expected.

With Sklearn-Optuna, you gain immediate access to sophisticated Bayesian optimization while maintaining full compatibility with Scikit-Learn's Pipeline, cross-validation, and serialization. Perfect for data scientists who want smarter hyperparameter search without learning a new API.

Note: This project is inspired by Optuna-Integration's OptunaSearchCV.

What are the features of Sklearn-Optuna?

  • Drop-in Scikit-Learn search: Extends BaseSearchCV and works with Pipeline, clone(), get_params()/set_params(), and any estimator
  • Smart optimization: TPE, CMA-ES, and other samplers explore the search space more efficiently than grid or random search
  • Flexible distributions: Optuna distributions (FloatDistribution, IntDistribution, CategoricalDistribution) for log-scaled, bounded, and categorical spaces
  • Study persistence: Pass a Storage backend to persist trials to a database, or resume optimization by passing an existing study to fit()
  • Callbacks: Attach Optuna callbacks (e.g., MaxTrialsCallback) to control optimization flow
  • Pruning: Pass a Pruner to stop trials that are reliably worse than the best one after a few folds, instead of running every fold
  • Nested pipeline search: Use OptunaSearchCV inside another OptunaSearchCV for hierarchical hyperparameter optimization

How to install Sklearn-Optuna?

Install the Sklearn-Optuna package using pip:

pip install sklearn_optuna

or using uv:

uv pip install sklearn_optuna

or using conda:

conda install -c conda-forge sklearn_optuna

or using mamba:

mamba install -c conda-forge sklearn_optuna

or alternatively, add sklearn_optuna to your requirements.txt or pyproject.toml file.

How to get started with Sklearn-Optuna?

1. Define a search space with Optuna distributions

from optuna.distributions import FloatDistribution
from sklearn.linear_model import LogisticRegression

param_distributions = {
    "C": FloatDistribution(1e-2, 10.0, log=True),
}

2. Create and fit an OptunaSearchCV

from sklearn_optuna import OptunaSearchCV, Sampler
import optuna

search = OptunaSearchCV(
    LogisticRegression(max_iter=200),
    param_distributions,
    n_trials=20,
    sampler=Sampler(sampler=optuna.samplers.TPESampler, seed=42),
    cv=5,
)
search.fit(X_train, y_train)

3. Inspect results

print(search.best_params_)   # {'C': 1.23}
print(search.best_score_)    # 0.95
search.best_estimator_.predict(X_test)

How do I use Sklearn-Optuna?

Full documentation is available at https://sklearn-optuna.readthedocs.io/.

Interactive examples are available in the examples/ directory:

Can I contribute?

We welcome contributions, feedback, and questions:

If you are interested in becoming a maintainer or taking a more active role, please reach out to Guillaume Tauzin on GitHub Discussions.

Where can I learn more?

For questions and discussions, you can also open a discussion.

License

This project is licensed under the terms of the Apache-2.0 License.

How do I cite Sklearn-Optuna?

If you use Sklearn-Optuna in work you publish, please cite it:

Guillaume Tauzin. Sklearn-Optuna: An Optuna integration for hyperparameter tuning in Scikit-Learn. https://github.com/stateful-y/sklearn-optuna

Or in BibTeX:

@software{sklearn_optuna,
  author  = "Guillaume Tauzin",
  title   = "{Sklearn-Optuna: An Optuna integration for hyperparameter tuning in Scikit-Learn}",
  url     = "https://github.com/stateful-y/sklearn-optuna",
  license = "Apache-2.0"
}

Reference managers can read CITATION.cff directly. To cite a specific version, see the citation page.

Acknowledgements

This project is maintained by stateful-y, an ML consultancy specializing in data science & engineering. If you're interested in collaborating or learning more about our services, please visit our website.

Made by stateful-y

Metadata

Release files for sklearn-optuna 0.1.0a6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sklearn-optuna 0.1.0a6
File Size Uploaded Provenance Actions
sklearn_optuna-0.1.0a6.tar.gz 426.9 kB With provenance Details for sklearn_optuna-0.1.0a6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sklearn-optuna 0.1.0a6
File Interpreter ABI Platform Actions
sklearn_optuna-0.1.0a6-py3-none-any.whl Python 3 none any Details for sklearn_optuna-0.1.0a6-py3-none-any.whl

Total release size: 450.5 kB

Release files / sklearn_optuna-0.1.0a6.tar.gz

Download URL sklearn_optuna-0.1.0a6.tar.gz
Size 426.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e080efe3614e0db9cb3f3683e70822672582a1f96f0a84def96eaee15b5d9db5
BLAKE2b-256 checksum
How to use checksums
ffd98da93c68eb178b8eebda6e96e31e8f0aeb7e5303da98607d677b924e5aa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / sklearn_optuna-0.1.0a6-py3-none-any.whl

Download URL sklearn_optuna-0.1.0a6-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b59ec1f9f82c9a16175394fba32e8b391b8701b79c7ac64e02940af20d82ce9
BLAKE2b-256 checksum
How to use checksums
61aeada3f7d46ff1a69604070e00612506be7a9195aed81ae1c016e354234694
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for sklearn-optuna 0.1.0a6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sklearn_optuna-0.1.0a6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page