Hyperactive
Hyperactive copied to clipboard
[ENH] Sktime regression integration
Summary
This PR adds integration for sktime time series regression, addressing . It introduces TSROptCV, enabling users to optimize sktime regressors using any Hyperactive optimizer (e.g., Random Search, Hill Climbing, Optuna TPE).
Key Changes
- Added
TSROptCVin_regression.py— a delegate regressor that wraps the Hyperactive optimization workflow. - Added
SktimeRegressionExperimentinsktime_regression.py— an adapter connecting sktime’sevaluate()function to Hyperactive’s experiment interface. - Exported
TSROptCVin__init__.py. - Added integration tests in
test_sktime_estimators.pyto ensure compatibility with the sktime estimator contract. - Minor update to
_BaseGFOadapterto exposebest_score_for consistency with other integrations.
API Usage
import numpy as np
from sktime.datasets import load_unit_test
from sktime.regression.distance_based import KNeighborsTimeSeriesRegressor
from hyperactive.integrations.sktime import TSROptCV
from hyperactive.opt import RandomSearch
# 1. Load data
X_train, y_train = load_unit_test(split="train", return_X_y=True)
X_test, y_test = load_unit_test(split="test", return_X_y=True)
# 2. Define estimator and search space
estimator = KNeighborsTimeSeriesRegressor()
search_space = {
"n_neighbors": list(range(1, 10)),
"weights": ["uniform", "distance"],
}
# 3. Initialize TSROptCV with a Hyperactive optimizer
tsr_opt = TSROptCV(
estimator=estimator,
optimizer=RandomSearch(search_space, n_iter=10),
cv=3,
n_jobs=1,
)
# 4. Run optimization
tsr_opt.fit(X_train, y_train)
# 5. Check best results
print("Best score:", tsr_opt.best_score_)
print("Best params:", tsr_opt.best_params_)
# 6. Predict using the optimized model
y_pred = tsr_opt.predict(X_test)
Testing
Fixes
Fixes #196
Hi @fkiraly !! Is it looks fine now ?