Skip to content

[ENH] forecasting test scenarios for categorical variables#5964

Open
fkiraly wants to merge 9 commits intomainfrom
object-dtype-test
Open

[ENH] forecasting test scenarios for categorical variables#5964
fkiraly wants to merge 9 commits intomainfrom
object-dtype-test

Conversation

@fkiraly
Copy link
Copy Markdown
Collaborator

@fkiraly fkiraly commented Feb 19, 2024

This PR adds two test scenarios for use of categorical variables in forecasting:

  • ForecasterFitPredictCategorical, with a categorical univariate y and no exogeneous data
  • ForecasterFitPredictCategoricalExog, with a mixed categorical/float exogeneous X, and float univariate y

Depends on #5886 which relaxes the pandas based types to allow categorical and object data.

FYI @yarnabrina - this test should systematically run all forecaster test parameter settings with the given input.

@fkiraly fkiraly added module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting module:tests test framework functionality - only framework, excl specific tests enhancement Adding new functionality labels Feb 19, 2024
@yarnabrina
Copy link
Copy Markdown
Member

I think you meant #5886 instead of #5962, so edited PR header accordingly. Please revert if that's not the case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am completely unfamiliar with this module, and do not know how do these get tested. So may be @benHeid / @achieveordie can review this one, I'm not eligible.

But I'll note that probably these changes allow categorical for classification/regression as well. So, may be that's also something you may want to test?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This module has scripted test scenarios with arguments to call fit and predict with, these are substituted in the scenarios argument of individual tests (methods) of TestAllForecasters.

The separation and tagging is needed, since not all estimators match with all scenarios.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But I'll note that probably these changes allow categorical for classification/regression as well. So, may be that's also something you may want to test?

Yes, I suppose - but only in the input X. Though, I would be fairly confident that if things work out well for forecastting, it will likely not be a problem in any other module. Of course not fully.

@fkiraly
Copy link
Copy Markdown
Collaborator Author

fkiraly commented Feb 19, 2024

I think you meant #5886 instead of #5962, so edited PR header accordingly.

Yes, of course, my bad - thanks.

@fkiraly
Copy link
Copy Markdown
Collaborator Author

fkiraly commented Feb 19, 2024

hm, that's quite a lot of failures - should we deal with this via tags, @yarnabrina?
Not sure how to tag, one perhaps for input and one for output?

@yarnabrina
Copy link
Copy Markdown
Member

Before I say anything, can you please help me understand what do these failures mean?

I am guessing that the failures come from the fact that some (majority I guess, if not all) forecasters do not support categorical features directly and will need some encoding (label - can't use, so one-hot?) transformation earlier. Is that it, or is there something else as well?

@fkiraly
Copy link
Copy Markdown
Collaborator Author

fkiraly commented Feb 19, 2024

I am guessing that the failures come from the fact that some (majority I guess, if not all) forecasters do not support categorical features directly and will need some encoding (label - can't use, so one-hot?) transformation earlier. Is that it, or is there something else as well?

I am guessing the same, but I'm also not sure.

My understanding of the failures:

  • most actually come from "within" the estimtator. That is, nothing in the boilerplate layer prevents the data from being passed to _fit etc anymore.
  • they failures look very distinct, hey look like specific to individual estimators

So yes, earlier transformation could prevent the failures, the main issue for me is that it doesn't juts fail, but fails with uninformative error.

@yarnabrina
Copy link
Copy Markdown
Member

We can try to create a new boolean tag, say support-categorical-features and set it as False by default. For different subclasses, e.g. reduction ones may override these as True, as XGBoost, CatBoost, etc. can accept categorical columns directly, though they may need specification of special arguments during __init__. We can check the value for this tag in base class, and fail quickly if the requirement is not satisfied.

What I do not like is depending on previous transformations any forecaster may actually be okay, becuase what is being passed at the end will not be numeric. I don't know if that can be detected or not. We can try to set this categorical support tag separately for input/output of a transformer, but don't know how these will work for non-sktime transformers (which are sklearn-compatible and used with TabularToSeriesAdaptor).

@fkiraly
Copy link
Copy Markdown
Collaborator Author

fkiraly commented Feb 20, 2024

What I do not like is depending on previous transformations any forecaster may actually be okay, becuase what is being passed at the end will not be numeric.

Can you give an example?

@yarnabrina
Copy link
Copy Markdown
Member

earlier transformation could prevent the failure

Meant this case, e.g. something like this from #5867 (comment):

pipeline = (ColumnSelect(columns=["Q"]) * OneHotEncoder()) ** (StandardScaler() * ARIMA())

(Plus output conversion tag change that you suggested in this case)

@fkiraly
Copy link
Copy Markdown
Collaborator Author

fkiraly commented Feb 20, 2024

yes, but that would work, no? The pipeline has the tag set to "supports", so nothing should break?

@yarnabrina
Copy link
Copy Markdown
Member

yes, but that would work, no? The pipeline has the tag set to "supports", so nothing should break?

I'm confused, how will pipeline has "caregorical support" tag as True?

By default, ARIMA has False. We can only change tgat value for pipeline to True if there is a transformation on all categorical column(s) to make them numerical. How shall we detect these?

  1. There's at least a transformation in the pipeline that can take categorical and convert to numerical (my doubt: we can't know behaviour of OneHotEncoder etc. with tags)
  2. Such transformations are applied on all categorical columns (my doubt: do we store each columns and their types and what all columns are being transformed)

@fkiraly
Copy link
Copy Markdown
Collaborator Author

fkiraly commented Feb 21, 2024

I'm confused, how will pipeline has "caregorical support" tag as True?

We'd just set it to True regardless, in the class.

So it would be wrong in some instances, e.g., sklearn components where we cannot detect, but the user will still receive an informative error message, namely where it first hits an sktime input check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adding new functionality module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting module:tests test framework functionality - only framework, excl specific tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants