Repository: keras-team/autokeras

Issue:
TimeSeriesForecaster



Discussion:
Has there been any development regarding this?
There are two possible approaches.
1. Put the preprocessing step inside the Keras model.
We need a preprocessing layer to change the shape.
The input shape to the preprocessing layer (num_instances, num_features).
The output shape of the preprocessing layer (num_instances - lookback + 1, lookback, num_features).
Is it possible to implement a preprocessing layer like this?

2. Do the preprocessing before input to the Keras model.
This can be directly done with input_adpaters.py.
The problem is when people export the Keras model, the model cannot do the preprocessing for them.
They have to do the preprocessing themselves to use the exported Keras model.
A possible solution would be to add one more argument for whether to do the preprocessing for the user in the fit.
They can choose to do preprocessing themselves when using AutoKeras.

@abgese 
I have got a reply confirming we cannot implement a preprocessing layer doing the job. Let's take the second approach to add a TimeSeriesInput() in nodes.py and a corresponding adapter in input_adapters.py.

Let me know if you have any questions.

I will be changing the API and docs for enabling users to do the preprocessing themselves.

We may use this feature later when it is in TensorFlow's stable release.
https://github.com/keras-team/governance/blob/master/rfcs/20190729-keras-preprocessing-redesign.md#timeseriesgenerator
@abgese I have merged the PR. I just found that there are still 2 minor changes we need to make.

1. We should change the default value of `predict_until`. Since we can know how long the user want to predict based on how long is the training and testing `x`. We just predict until the end of the `x`.

2. I am a little bit confused about why we don't need `y` in the `predict` function. I think the previous `y`s are also part of the input to predict the next step.

Thanks.

Resolving patch:
diff --git a/autokeras/tasks/time_series_forecaster.py b/autokeras/tasks/time_series_forecaster.py
--- a/autokeras/tasks/time_series_forecaster.py
+++ b/autokeras/tasks/time_series_forecaster.py
@@ -15,7 +15,7 @@ def __init__(self,
                  column_types=None,
                  lookback=None,
                  predict_from=1,
-                 predict_until=10,
+                 predict_until=None,
                  **kwargs):
         inputs = input_module.TimeseriesInput(lookback=lookback,
                                               column_names=column_names,
@@ -68,6 +68,8 @@ def predict(self, x, batch_size=32, **kwargs):
                                  batch_size=batch_size,
                                  **kwargs)
         lower_bound = self.train_len + self.predict_from
+        if self.predict_until is None:
+            self.predict_until = len(y_pred)
         upper_bound = min(self.train_len + self.predict_until + 1, len(y_pred))
         return y_pred[lower_bound:upper_bound]
 
@@ -122,7 +124,8 @@ class TimeseriesForecaster(SupervisedTimeseriesDataPipeline):
         predict_until: Int. The end point of the forecast for each sample (in number
             of steps) after the last time step in the input. If N is the last step in
             the input, then the last step of the predicted output will be
-            N + predict_until. Defaults to 10.
+            N + predict_until. If unspecified, it will predict till end of dataset.
+            Defaults to None.
         loss: A Keras loss function. Defaults to use 'mean_squared_error'.
         metrics: A list of Keras metrics. Defaults to use 'mean_squared_error'.
         project_name: String. The name of the AutoModel. Defaults to
@@ -147,7 +150,7 @@ def __init__(self,
                  column_types=None,
                  lookback=None,
                  predict_from=1,
-                 predict_until=10,
+                 predict_until=None,
                  loss='mean_squared_error',
                  metrics=None,
                  project_name='time_series_forecaster',
@@ -310,7 +313,8 @@ class TimeseriesClassifier(SupervisedTimeseriesDataPipeline):
         predict_until: Int. The end point of the forecast for each sample (in number
             of steps) after the last time step in the input. If N is the last step in
             the input, then the last step of the predicted output will be
-            N + predict_until. Defaults to 10.
+            N + predict_until. If unspecified, it will predict till end of dataset.
+            Defaults to None.
         loss: A Keras loss function. Defaults to use 'mean_squared_error'.
         metrics: A list of Keras metrics. Defaults to use 'mean_squared_error'.
         project_name: String. The name of the AutoModel. Defaults to
@@ -335,7 +339,7 @@ def __init__(self,
                  column_types=None,
                  lookback=None,
                  predict_from=1,
-                 predict_until=10,
+                 predict_until=None,
                  loss='mean_squared_error',
                  metrics=None,
                  project_name='time_series_classifier',


Test patch: