autokeras icon indicating copy to clipboard operation
autokeras copied to clipboard

Bug: TimeseriesForecaster predicting fails on KeyError

Open gstaron opened this issue 2 years ago • 0 comments

Bug Description

TimeseriesForecaster predicting fails: Traceback (most recent call last): File "../ak.py", line 156, in predictions = clf.predict(pred_data) File "../venv_ak/lib/python3.8/site-packages/autokeras/tasks/time_series_forecaster.py", line 289, in predict return super().predict(x=x, **kwargs) File "../venv_ak/lib/python3.8/site-packages/autokeras/tasks/time_series_forecaster.py", line 106, in predict y_pred = super().predict(x=x, **kwargs) File "../venv_ak/lib/python3.8/site-packages/autokeras/tasks/structured_data.py", line 165, in predict return super().predict(x=x, **kwargs) File "../venv_ak/lib/python3.8/site-packages/autokeras/auto_model.py", line 451, in predict pipeline = self.tuner.get_best_pipeline() File "../venv_ak/lib/python3.8/site-packages/autokeras/engine/tuner.py", line 67, in get_best_pipeline return pipeline_module.load_pipeline(self.best_pipeline_path) File "../venv_ak/lib/python3.8/site-packages/autokeras/pipeline.py", line 77, in load_pipeline return Pipeline.from_config(io_utils.load_json(filepath)) File "../venv_ak/lib/python3.8/site-packages/autokeras/pipeline.py", line 183, in from_config inputs=[ File "../venv_ak/lib/python3.8/site-packages/autokeras/pipeline.py", line 184, in [ File "../venv_ak/lib/python3.8/site-packages/autokeras/pipeline.py", line 185, in preprocessors_module.deserialize(preprocessor) File "../venv_ak/lib/python3.8/site-packages/autokeras/preprocessors/init.py", line 34, in deserialize return keras.utils.deserialize_keras_object( File "../venv_ak/lib/python3.8/site-packages/keras/utils/generic_utils.py", line 686, in deserialize_keras_object deserialized_obj = cls.from_config(cls_config) File "../venv_ak/lib/python3.8/site-packages/autokeras/preprocessors/common.py", line 151, in from_config obj = cls(**init_config) File "../venv_ak/lib/python3.8/site-packages/autokeras/preprocessors/common.py", line 113, in init column_type = self.column_types[column_name] KeyError: 0

Bug Reproduction

Code for reproducing the bug: clf = ak.TimeseriesForecaster( lookback=lookback, predict_until=rebalance_freq, metrics=metrics_fns, objective=kt.Objective(f"val_{metrics[0]}", direction="max"), directory=models_path )

clf.fit( x=data_x_train, y=data_y_train, validation_data=(data_x_val, data_y_val), batch_size=BATCH_SIZE )

with keras.utils.custom_object_scope(helper.objectives): pred_data = data_x_test.loc[data_x_test.index.get_level_values(level=0) < end_train] predictions = clf.predict(pred_data)

Data used by the code: pred_data: columns: Date,,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97 rows: 1992-12-28,AAPL, 1992-12-28,FB, .. elements: floats

Expected Behavior

Predicting future predict_until data points.

Setup Details

Include the details about the versions of:

  • OS type and version: Ubuntu 20.04.4 LTS (Focal Fossa)
  • Python: 3.8.10
  • autokeras: 1.0.19
  • keras-tuner: 1.1.2
  • scikit-learn: 1.1.1
  • numpy: 1.23.0
  • pandas: 1.4.3
  • tensorflow: 2.9.1

Additional context

Workaround in autokeras/autokeras/preprocessors/common.py - change line 112: try: column_type = self.column_types[column_name] except KeyError as ke: print(f"KeyError: {ke}, using string key..") column_type = self.column_types[str(column_name)]

gstaron avatar Jun 27 '22 19:06 gstaron