最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Error when performing ForecastingGridSearchCV - Stack Overflow

programmeradmin5浏览0评论

I'm trying to perform scaling on both y and X before fitting the forecast model. I want to make the scaling transformation optional. However, I encountered an error when performing the grid search above.

from sklearn.preprocessing import MinMaxScaler, PowerTransformer, RobustScaler
from sktime.performance_metrics.forecasting import MeanSquaredError
from sktime.forecasting.statsforecast import StatsForecastAutoARIMA
from sktime.forecasting.model_selection import ExpandingWindowSplitter
from sktime.forecastingpose import ForecastingPipeline
from sktime.forecasting.fbprophet import Prophet

train1

y   M0  Delta
ds          
2022-10 127 249.0   14.0
2022-11 194 298.0   160.0
2022-12 202 269.0   128.0
2023-01 149 215.0   33.0
2023-02 203 198.0   111.0
2023-03 222 259.0   10.0
2023-04 195 232.0   -1.0
2023-05 236 210.0   47.0
2023-06 76  155.0   -12.0
2023-07 204 232.0   101.0
2023-08 231 221.0   -13.0
2023-09 171 196.0   -30.0
2023-10 172 80.0    39.0
2023-11 173 206.0   1.0
2023-12 132 189.0   -8.0
2024-01 165 190.0   50.0
2024-02 93  136.0   0.0
2024-03 105 126.0   45.0
2024-04 99  134.0   18.0
2024-05 121 128.0   12.0
2024-06 109 181.0   0.0
2024-07 183 244.0   7.0
2024-08 159 195.0   27.0
2024-09 147 186.0   -5.0

test1

M0  Delta
ds      
2024-10 161.0   -10.0

Forecasting Pipeline

pipe_y = TransformedTargetForecaster(
        steps=[
            ("scaler", OptionalPassthrough(TabularToSeriesAdaptor(RobustScaler()))),
            ("forecaster", StatsForecastAutoARIMA(sp=12)),
        ]
    )
pipe_X = ForecastingPipeline(
    steps=[
        ("scaler", OptionalPassthrough(TabularToSeriesAdaptor(RobustScaler()))),
        ("forecaster", pipe_y),
    ]
)

cv1 = ExpandingWindowSplitter(fh=[1], initial_window=train1.shape[0]-3, step_length=1)

gscv1 = ForecastingGridSearchCV(
    forecaster=pipe_X,
    param_grid=[
        {
            "scaler__passthrough": [True, False],
            "forecaster__scaler__passthrough": [True, False],
            "forecaster": [StatsForecastAutoARIMA(sp=12)],
            },
        {
            "scaler__passthrough": [True, False],
            "forecaster": [Prophet()],
            "forecaster__scaler__passthrough": [True, False],
            "forecaster__seasonality_mode": ['addictive','multiplicative'],
            "forecaster__changepoint_prior_scale": [0.001, 0.01, 0.1, 0.5],
            "forecaster__seasonality_prior_scale": [0.01, 0.1, 1.0, 10.0],
            },
        ],
    cv=cv1,
    error_score="raise",
    scoring=MeanSquaredError(square_root=True),
)

gscv1.fit(train1['y'], X=train1[features1])

Error Traceback

---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "c:\Desktop\Waterfall Chart\lib\site-packages\joblib\externals\loky\process_executor.py", line 463, in _process_worker
    r = call_item()
  File "c:\Desktop\Waterfall Chart\lib\site-packages\joblib\externals\loky\process_executor.py", line 291, in __call__
    return self.fn(*self.args, **self.kwargs)
  File "c:\Desktop\Waterfall Chart\lib\site-packages\joblib\parallel.py", line 598, in __call__
    return [func(*args, **kwargs)
  File "c:\Desktop\Waterfall Chart\lib\site-packages\joblib\parallel.py", line 598, in <listcomp>
    return [func(*args, **kwargs)
  File "c:\Desktop\Waterfall Chart\lib\site-packages\sktime\forecasting\model_selection\_tune.py", line 368, in _fit_and_score
    forecaster.set_params(**params)
  File "c:\Desktop\Waterfall Chart\lib\site-packages\sktime\base\_meta.py", line 60, in set_params
    self._set_params(steps_attr, **kwargs)
  File "c:\Desktop\Waterfall Chart\lib\site-packages\sktime\base\_meta.py", line 142, in _set_params
    super().set_params(**params)
  File "c:\Desktop\Waterfall Chart\lib\site-packages\skbase\base\_base.py", line 398, in set_params
    unmatched_params = {key: params[key] for key in unmatched_keys}
  File "c:\Desktop\Waterfall Chart\lib\site-packages\skbase\base\_base.py", line 398, in <dictcomp>
    unmatched_params = {key: params[key] for key in unmatched_keys}
KeyError: 'estimator'
"""
...
--> 763         raise self._result
    764     return self._result
    765 finally:

KeyError: 'estimator'

I'm trying to follow the automl example in the link below: .html

发布评论

评论列表(0)

  1. 暂无评论