Skip to content
Advertisement

Error in implementing autokeras timeseries model

I was trying to implement autokeras TimeSeriesForecaster on a serial dataset. The features and label of the dataset are respectively given below.

df1_x = enter image description here

df1_y = 
0    2.5
1    2.1
2    2.2
3    2.2
4    1.5
Name: target_carbon_monoxide, dtype: float64

AutoML preparation

#parameters
predict_from = 1
predict_until = 1
lookback = 3
clf = ak.TimeseriesForecaster(
    lookback=lookback,
    predict_from=predict_from,
    predict_until=predict_until,
    max_trials=1,
    objective="val_loss",
)
# Train the TimeSeriesForecaster with train data
clf.fit(
    x=df1_x,
    y=df1_y,
    epochs=10,
)

The dataframe has no NaN values, the shape of the features dataframe is (7111, 8) i.e. a 2D dataframe.

But the error came as following:

Search: Running Trial #1

Hyperparameter    |Value             |Best Value So Far 
timeseries_bloc...|True              |?                 
timeseries_bloc...|lstm              |?                 
timeseries_bloc...|3                 |?                 
regression_head...|0                 |?                 
optimizer         |adam              |?                 
learning_rate     |0.001             |?                 

Epoch 1/10
    173/Unknown - 4s 5ms/step - loss: 2.2421 - mean_squared_error: 2.2421
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
/tmp/ipykernel_11292/1163792963.py in <module>
     10 )
     11 # Train the TimeSeriesForecaster with train data
---> 12 clf.fit(
     13     x=df1_x,
     14     y=df1_y,

InvalidArgumentError:  Incompatible shapes: [32,1] vs. [30,1]
     [[node mean_squared_error/SquaredDifference (defined at home/samar/.local/lib/python3.8/site-packages/autokeras/utils/utils.py:88) ]] [Op:__inference_train_function_13895]

Function call stack:
train_function

Advertisement

Answer

You need to provide validation data to the fit(). If you split the data you have (df1) to trainset and validation, and provide both of them to fit(), the training will work well. Try using train_test_split to split your data, or you could do it manually. your code would be something like that:

from sklearn.model_selection import train_test_split
df1_x, df1_x_eval, df1_y, df1_y_eval = train_test_split(df1_x, df1_y, test_size=0.25, random_state=42)
clf.fit(
    x=df1_x,
    y=df1_y,
    validation_data = (df_x_eval, df_y_eval),
    epochs=10)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement