Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoETS Exception no model able to be fitted #929

Closed
webert6 opened this issue Oct 15, 2024 · 4 comments
Closed

AutoETS Exception no model able to be fitted #929

webert6 opened this issue Oct 15, 2024 · 4 comments
Labels

Comments

@webert6
Copy link

webert6 commented Oct 15, 2024

What happened + What you expected to happen

I have am getting this error unexpectedly. This data doesn't look to have any issues with it that would lead me to believe ETS would have issues.

Traceback (most recent call last):
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/fugue_spark/execution_engine.py", line 228, in _udf_pandas
output_df = map_func(cursor, input_df)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/fugue/extensions/_builtins/processors.py", line 333, in run
return self.transformer.transform(df)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/fugue/extensions/transformer/convert.py", line 346, in transform
return self._wrapper.run(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/fugue/dataframe/function_wrapper.py", line 103, in run
rt = self._func(**rargs)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/distributed/fugue.py", line 139, in _forecast_noX
_, result = self._forecast(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/distributed/fugue.py", line 110, in _forecast
result = model.forecast(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/core.py", line 939, in forecast
res_fcsts = self.ga.forecast(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/core.py", line 204, in forecast
raise error
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/core.py", line 204, in forecast
raise error
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/models.py", line 799, in forecast
res = self._add_conformal_intervals(fcst=res, y=y, X=X, level=level)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/models.py", line 167, in _add_conformal_intervals
cs = self._conformity_scores(y, X) if y is not None else self._cs
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/models.py", line 153, in _conformity_scores
fcst_window = self.forecast(h=h, y=y_train, X=X_train, X_future=X_test) # type: ignore[attr-defined]
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/models.py", line 788, in forecast
mod = ets_f(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/statsforecast/ets.py", line 922, in ets_f
raise Exception("no model able to be fitted")
Exception: no model able to be fitted

Versions / Dependencies

Click to expand Dependencies: statsforecast==1.7.6 and greater

Reproducible example

data = [
  (1,   "2024-01-01", 1),
  (1, "2023-12-01", 2),
  (1, "2023-11-01", 2),
  (1, "2023-10-01", 7),
  (1, "2023-09-01", 6),
  (1, "2023-08-01", 7),
  (1, "2023-07-01", 12),
  (1, "2023-06-01", 4),
  (1, "2023-05-01", 9),
  (1, "2023-04-01", 2),
  (1, "2023-03-01", 2),
  (1, "2023-02-01", 0),
  (1, "2023-01-01", 1),
  (1, "2022-12-01", 2),
  (1, "2022-11-01", 5),
  (1, "2022-10-01", 6),
  (1, "2022-09-01", 4),
  (1, "2022-08-01", 5),
  (1, "2022-07-01", 4),
  (1, "2022-06-01", 10),
  (1, "2022-05-01", 2),
  (1, "2022-04-01", 2),
  (1, "2022-03-01", 1),
  (1, "2022-02-01", 1),
  (1, "2022-01-01", 1),
  (1, "2021-12-01", 0),
  (1, "2021-11-01", 2),
  (1, "2021-10-01", 4),
  (1, "2021-09-01", 1),
  (1, "2021-08-01", 1),
  (1, "2021-07-01", 1),
  (1, "2021-06-01", 2),
  (1, "2021-05-01", 1),
  (1, "2021-04-01", 3),
  (1, "2021-03-01", 5),
  (1, "2021-02-01", 3),
]


from pyspark.sql import SparkSession
from statsforecast.models import *
from statsforecast.utils import ConformalIntervals
from statsforecast import StatsForecast

# Initialize Spark session
spark = SparkSession.builder \
    .appName("Create DataFrame from Array") \
    .getOrCreate()

# Define the schema
columns = ["unique_id", "ds", "y"]

# Create the DataFrame
df = spark.createDataFrame(data, schema=columns)

horizon = 2

model_params = [AutoETS(season_length= 12, model='AAA', damped=True, prediction_intervals=ConformalIntervals(h=horizon, n_windows=9), alias='AUTO_ETS_AAdA')]

sf = StatsForecast(
    models=model_params,
    freq="MS"
)

forecasts = sf.forecast(
    df=df , 
    h=horizon, 
    level=[50,60,70,80,90,95,99]
)

# to invoke the actual model
forecasts.toPandas()

Issue Severity

Medium: It is a significant difficulty but I can work around it.

@webert6 webert6 added the bug label Oct 15, 2024
@webert6
Copy link
Author

webert6 commented Oct 15, 2024

by removing the parameter prediction_intervals=ConformalIntervals(h=horizon, n_windows=9) entirely the model works as expected. Conformal intervals are required for my use case tho.

@webert6
Copy link
Author

webert6 commented Oct 15, 2024

If I change the n_windows parameter in ConformalIntervals() from 9 to something less, it works. From my understanding, the training data needs to be at least h * n_windows + 2 rows long so this must be different for ETS models?

@jmoralez
Copy link
Member

Hey. Seasonal models require at least 2 seasonal periods as history (24 samples in your case) and you're forcing it to be a seasonal model, which is most likely why it fails. Can you try setting the seasonal part as auto (model='AAZ')?

@webert6
Copy link
Author

webert6 commented Oct 28, 2024

Great insight @jmoralez that makes sense. 9 was too many windows. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants