Skip to content

[ENH] Standardise check_y use case #2970

@TonyBagnall

Description

@TonyBagnall

Describe the feature or idea you want to propose

Further to #2958

several base classes have check_y functionality. We cannot really generalise this, since there are different constraints on different tasks. However, we can standardise the use case. Currently there are two models

self._check_y(y) or self._check_y(y, n_cases=self.metadata_["n_cases"])

this simply checks that y is a compliant type and shape for the task in question. This is used in BaseClassifier, both BaseTransformer classes, BaseSegmenter (after #2958). Other case is

y = self._check_y(y) or y = self._check_y(y, self.metadata_["n_cases"])

this is used in BaseRegressor as follows

        if isinstance(y, pd.Series):
            y = pd.Series.to_numpy(y)
        return y.astype(float)

and the two BaseAnomalyDetector classes, where it gets converted to numpy booleans.

Describe your proposed solution

I think conversion should be by a separate function convert_y and standard usage would be

self._check_y(y)
y = self._convert_y(y)

Describe alternatives you've considered, if relevant

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature, improvement request or other non-bug code enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions