Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Support sklearn.compose.TransformedTargetRegressor #240

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tune_sklearn/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from collections import defaultdict
from typing import Dict

from sklearn.base import RegressorMixin
from sklearn.compose import TransformedTargetRegressor
from sklearn.metrics import check_scoring
from sklearn.pipeline import Pipeline

from tune_sklearn._detect_booster import (
is_xgboost_model, is_lightgbm_model_of_required_version, is_catboost_model)
import numpy as np
Expand Down Expand Up @@ -101,6 +103,14 @@ def get_early_stop_type(estimator, early_stopping):

if not early_stopping:
return EarlyStopping.NO_EARLY_STOP

if check_is_pipeline(estimator):
for step_name, step in estimator.steps:
Copy link
Member

@Yard1 Yard1 Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three things:

  • we shouldn't be only checking for regressors
  • this is not foolproof & goes against duck typing principle of sklearn
  • we can just assume that the last step of the pipeline is an estimator. You can't really make a pipeline with multiple estimators.

is_regressor = isinstance(step, RegressorMixin)
if is_regressor:
estimator = step
break

can_partial_fit = check_partial_fit(estimator)
can_warm_start_iter = check_warm_start_iter(estimator)
can_warm_start_ensemble = check_warm_start_ensemble(estimator)
Expand Down