autokeras icon indicating copy to clipboard operation
autokeras copied to clipboard

TimeSeriesForecaster: Predict function returns ValueError

Open sparkey63 opened this issue 3 years ago • 5 comments

Hi,

I've been using AutoKeras for Time Series forecasting but when the model has been trained and I apply the test data, it raises: "ValueError: The prediction data requires the original training data to make predictions on subsequent data points" but I can't put both the test data and the training data as separate arguments? Do I need to append the test data to the training data for the model to predict or is there something I'm missing?

Setup Details

  • OS type and version: Windows 10
  • Python: 3.9
  • autokeras: 1.0.16
  • keras-tuner: 1.0.4
  • scikit-learn: 1.0
  • numpy: 1.19.5
  • pandas: 1.3.4
  • tensorflow: 2.5.0 (GPU)

sparkey63 avatar Oct 23 '21 17:10 sparkey63

I also want to know why it is required that original training data must be present on test data (out of sample test). This way, how it could be used to predict out of sample in production environment? Should I append the original training data to every new input for predicting?

ericleonardo avatar Nov 19 '21 23:11 ericleonardo

Please, how to predict TimeSeriesForecaster on out of sample test without including original training samples to it? @haifeng-jin

ericleonardo avatar Nov 20 '21 00:11 ericleonardo

Ok.. I got to make it work on test data.. Must export the trained model. Then, load the exported model and predict on test data with it. We can evaluate the model on test data withou exporting it by:

print(clf.evaluate(X_test, y_test))

To export the model after training it. For a "clf" model:

import autokeras as ak
import tensorflow as tf
from tensorflow.keras.models import load_model

model = clf.export_model()

try:
    model.save("model_autokeras", save_format="tf")
except Exception:
    model.save("model_autokeras.h5")

loaded_model = load_model("model_autokeras", custom_objects=ak.CUSTOM_OBJECTS)

predicted_y = loaded_model.predict(tf.expand_dims(X_test,1), batch_size = 32)  #batch_sizer here is the same used for train

ericleonardo avatar Nov 20 '21 19:11 ericleonardo

Over a year later and I'm also getting this issue. Seems oddly sudden because it was working previously but the suggested fix above isn't working for me. Any update on this issue or what is causing it?

1kuna avatar Mar 01 '23 01:03 1kuna

Over a year later and I'm also getting this issue. Seems oddly sudden because it was working previously but the suggested fix above isn't working for me. Any update on this issue or what is causing it?

I was able to solve my issue by clearing the session using tf.keras.backend.clear_session() and reinitializing my model without using the fit method. Hope this helps.

1kuna avatar Mar 01 '23 20:03 1kuna