I am using lstm for weather prediction, in google colab using python and tensorflow & panda. The snippet of code that gives error is in the creation of univariate model as follows(image attached as well):
univariate_past_history = 20
univariate_future_target = 0
x_train_uni, y_train_uni = univariate_data(uni_data, 0, TRAIN_SPLIT,
univariate_past_history,
univariate_future_target)
x_val_uni, y_val_uni = univariate_data(uni_data, TRAIN_SPLIT, None,
univariate_past_history,
univariate_future_target)
The error is
IndexError Traceback (most recent call last)
<ipython-input-14-b832595cabf2> in <module>
4 x_train_uni, y_train_uni = univariate_data(uni_data, 0, TRAIN_SPLIT,
5 univariate_past_history,
----> 6 univariate_future_target)
7 x_val_uni, y_val_uni = univariate_data(uni_data, TRAIN_SPLIT, None,
8 univariate_past_history,
<ipython-input-5-fd6d6cf9af09> in univariate_data(dataset, start_index, end_index, history_size, target_size)
11 # Reshape data from (history_size,) to (history_size, 1)
12 data.append(np.reshape(dataset[indices], (history_size, 1)))
---> 13 labels.append(dataset[i+target_size])
14 return np.array(data), np.array(labels)
IndexError: index 4557 is out of bounds for axis 0 with size 4557
[Error][1]
The function used above is as follows:
def univariate_data(dataset, start_index, end_index, history_size, target_size):
data = []
labels = []
start_index = start_index + history_size
if end_index is None:
end_index = len(dataset) - target_size
for i in range(start_index, end_index):
indices = range(i-history_size, i)
# Reshape data from (history_size,) to (history_size, 1)
data.append(np.reshape(dataset[indices], (history_size, 1)))
labels.append(dataset[i+target_size])
return np.array(data), np.array(labels)
The data I am using is 4558*16 csv file in which some values are zeros and other are empty as well. Any help is appreciated. Thanks. [1]: https://i.stack.imgur.com/K3QIy.jpg