Hyperactive icon indicating copy to clipboard operation
Hyperactive copied to clipboard

[ENH] Sktime regression integration

Open Omswastik-11 opened this issue 1 month ago • 1 comments

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 TSROptCV in _regression.py — a delegate regressor that wraps the Hyperactive optimization workflow.
  • Added SktimeRegressionExperiment in sktime_regression.py — an adapter connecting sktime’s evaluate() function to Hyperactive’s experiment interface.
  • Exported TSROptCV in __init__.py.
  • Added integration tests in test_sktime_estimators.py to ensure compatibility with the sktime estimator contract.
  • Minor update to _BaseGFOadapter to expose best_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


Screenshot 2025-11-23 193751

Fixes


Fixes #196

Omswastik-11 avatar Nov 23 '25 14:11 Omswastik-11

Hi @fkiraly !! Is it looks fine now ?

Omswastik-11 avatar Dec 02 '25 08:12 Omswastik-11