How can I have a series of numpy ndarrays as the input data to train a tensorflow machine learning model?

Viewed 62

I am trying to build a machine learning model which predicts a single number from a series of numbers. I am using a Sequential model from the keras API of Tensorflow.

Basically my x data is a Pandas series which contains numpy ndarrays, which contain floats. My y data is a series of numpy ndarrays of shape (1,1), so basically just a single float value.

You can imagine my dataset to look something like this:

Index x data (pandas series) y data (pandas series)
0 np.ndarray(shape (1209278,) ) np.ndarray(shape = () )
1 np.ndarray(shape (1211140,) ) np.ndarray(shape = () )
2 np.ndarray(shape (1418411,) ) np.ndarray(shape = () )
3 np.ndarray(shape (1077132,) ) np.ndarray(shape = () )
... ... ...

The type of my x data and y data is, as stated above, a pandas series. When I try to train my model using the fit function it yields this error:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

I also tried converting the pandas series to a numpy array, but this did not help. As it seems, the fact that I have a series of differently shaped ndarrays as my input data is the problem itself.

I don't really know what I can do, to fix this error. Which leads me to my question:

How can I have a series of numpy ndarrays as the input data to train a tensorflow machine learning model?

1 Answers

Pandas Data Series does not support a direct conversion to tensors. So I would try first to convert those to list:

X = X.to_list()
Y = Y.to_list()
Related