scikit-learn / scikit-learn/scikit-learn
Allow NaNs for the target values in TransformedTargetRegressor
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 67.3k
- Forks
- 27.4k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 58
Description
Description
One potential use case for TransformedTargetRegressor is to get rid of missing values in the target. but currently initial check of the fit method doesn't allow such array.
Steps/Code to Reproduce
Example:
from sklearn.compose import TransformedTargetRegressor
from sklearn.impute import SimpleImputer
from sklearn.tree import DecisionTreeRegressor
from sklearn import datasets
X, y = datasets.load_linnerud(return_X_y=True)
## put some NaN in y
y[5, 1] = np.NaN
estimator = TransformedTargetRegressor(
regressor=DecisionTreeRegressor(),
func = lambda _y: SimpleImputer().fit_transform(_y), # becuse SimpleImputer doesnt have inverse
inverse_func = lambda _y: _y,
check_inverse = False
)
estimator.fit(X, y)
This raises:
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in sklearn/compose/_target.py around the initial check in TransformedTargetRegressor.fit, then inspect the provided reproduction using SimpleImputer and DecisionTreeRegressor. Determine how target NaNs should be handled while preserving the transformer behavior, and verify the reproduction no longer raises the reported ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100