{"id":4374,"library":"optuna-integration","title":"Optuna Integration","description":"Optuna Integration is a Python package that provides extended functionalities for Optuna, an automatic hyperparameter optimization software framework, in combination with various third-party machine learning libraries such as PyTorch, scikit-learn, and TensorFlow. It allows users to seamlessly integrate Optuna's powerful optimization capabilities and pruning mechanisms into their existing ML workflows. The library is currently at version 4.8.0, actively maintained, and follows Optuna's release cadence, typically with multiple releases per major Optuna version.","status":"active","version":"4.8.0","language":"en","source_language":"en","source_url":"https://github.com/optuna/optuna-integration","tags":["hyperparameter-optimization","machine-learning","deep-learning","optuna","scikit-learn","pytorch","tensorflow","lightgbm"],"install":[{"cmd":"pip install optuna-integration","lang":"bash","label":"Install core optuna-integration"},{"cmd":"pip install optuna-integration[sklearn]","lang":"bash","label":"Install with scikit-learn dependencies"},{"cmd":"pip install optuna-integration[lightgbm]","lang":"bash","label":"Install with LightGBM dependencies"}],"dependencies":[{"reason":"Core hyperparameter optimization framework.","package":"optuna","optional":false},{"reason":"Required for scikit-learn integrations (e.g., OptunaSearchCV).","package":"scikit-learn","optional":true},{"reason":"Required for LightGBM integrations (e.g., LightGBMTuner).","package":"lightgbm","optional":true},{"reason":"Required for PyTorch integrations.","package":"pytorch","optional":true},{"reason":"Required for TensorFlow/Keras integrations.","package":"tensorflow","optional":true}],"imports":[{"note":"Integration modules have officially migrated from `optuna.integration` to `optuna_integration` for better separation and maintainability. While the old path might still work for backward compatibility, the new path is recommended.","wrong":"from optuna.integration import OptunaSearchCV","symbol":"OptunaSearchCV","correct":"from optuna_integration.sklearn import OptunaSearchCV"},{"note":"As with `OptunaSearchCV`, LightGBM integration classes have moved to the `optuna_integration` package.","wrong":"from optuna.integration import LightGBMTuner","symbol":"LightGBMTuner","correct":"from optuna_integration.lightgbm import LightGBMTuner"}],"quickstart":{"code":"import optuna\nfrom optuna_integration.sklearn import OptunaSearchCV\nfrom sklearn.datasets import load_iris\nfrom sklearn.svm import SVC\nfrom sklearn.model_selection import train_test_split\n\ndef objective_svc(trial):\n    svc_c = trial.suggest_float('svc_c', 1e-10, 1e10, log=True)\n    svc_gamma = trial.suggest_float('svc_gamma', 1e-10, 1e10, log=True)\n    classifier_obj = SVC(C=svc_c, gamma=svc_gamma)\n    X, y = load_iris(return_X_y=True)\n    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)\n    classifier_obj.fit(X_train, y_train)\n    return classifier_obj.score(X_test, y_test)\n\n# Using OptunaSearchCV for a scikit-learn estimator\n# This automatically creates an Optuna study and optimizes the hyperparameters\noptuna_search = OptunaSearchCV(\n    estimator=SVC(gamma='auto', random_state=0),\n    param_distributions={\n        'C': optuna.distributions.FloatDistribution(1e-10, 1e10, log=True),\n        'kernel': ['linear', 'rbf']\n    },\n    n_trials=10,\n    random_state=0,\n    cv=3\n)\nX, y = load_iris(return_X_y=True)\noptuna_search.fit(X, y)\n\nprint(f\"Best parameters found by OptunaSearchCV: {optuna_search.best_params_}\")\nprint(f\"Best score found by OptunaSearchCV: {optuna_search.best_score_}\")","lang":"python","description":"This quickstart demonstrates how to use `OptunaSearchCV` from `optuna_integration.sklearn` to perform hyperparameter optimization for a scikit-learn `SVC` estimator. It defines a search space for the 'C' and 'kernel' parameters and runs a specified number of trials. The example also implicitly shows how an objective function for Optuna works for direct `study.optimize` usage (though `OptunaSearchCV` abstracts this for scikit-learn models)."},"warnings":[{"fix":"Update import statements from `from optuna.integration import ...` to `from optuna_integration import ...`.","message":"The integration modules have been migrated from the main `optuna` package to `optuna-integration`. Importing from `optuna.integration` is deprecated and will eventually be removed.","severity":"breaking","affected_versions":"Optuna 4.x and optuna-integration 1.0.0+"},{"fix":"Ensure your Python environment is version 3.9 or higher.","message":"Optuna (and by extension, optuna-integration) dropped support for Python 3.8 starting with Optuna 4.0.0.","severity":"breaking","affected_versions":"Optuna 4.0.0+ / optuna-integration 4.0.0+"},{"fix":"Replace `LightGBMTuner(..., verbosity=...)` with `tuner = LightGBMTuner(...)` followed by `tuner.set_verbosity(...)`.","message":"The `verbosity` argument in `LightGBMTuner` has been removed. Use the `set_verbosity` method instead to control logging levels.","severity":"deprecated","affected_versions":"Optuna 4.3.0+ / optuna-integration 4.3.0+"},{"fix":"Carefully review the documentation of the integrated estimator regarding its compatibility with scikit-learn's cross-validation utilities and potential data transformation needs.","message":"When using `OptunaSearchCV` with `cv` (cross-validation), ensure the underlying estimator can handle the data splits without issues. Some estimators might require specific random states or data types.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}