Hello,
I’m new to pytorch and would like to experiment on a timeseries forecasting problem. My training data consists monthly sales data, a three month moving average, as well as a flag denoting if a sales promotion is happening or not. I am trying to forecast for the next 12 months out.
My training data consists of 37 observations, six lags of all three features with size (37, 6, 3)
. My target data set is the next 12 months of sales data with size (37, 12)
.
When I try to convert my arrays into a torch.tensor using the below code, I get the below error:
Xtrain_val_tens = torch.tensor(Xtrain_val, dtype=torch.float64)
Ytrain_val_tens = torch.tensor(Ytrain_val, dtype = torch.float64)
ERROR
TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.
I tried the below with no luck:
Xtrain_val_tens = torch.from_numpy(Xtrain_val)
Ytrain_val_tens = torch.from_numpy(Ytrain_val)
If it helps, I start with a dataframe and put said df through the following code to get my arrays:
lags = 6
horizon = 12
###############Make a multi-output time series dataset#####################
series = samp_df[['ord_qty', '3_day_moving_avg', 'promotion_flag']]
#number of lags in the input
Tx = lags
#number of steps in the output
Ty = horizon
#instantiate list to take in the train (X) and test(Y) data set
X = []
Y = []
# run a series from 0 to the length of the dataframe minus the horizon to create a "step through time" data set
for t in range(len(series) - Tx - Ty + 1):
x = series[t:t+Tx]
X.append(x)
y = series['ord_qty'][t+Tx:t+Tx+Ty]
Y.append(y)
# #reshape into numpy arrays for faster processing in ML models
X = np.array(X)
Y = np.array(Y).reshape(-1, Ty)
Xtrain_val, Ytrain_val = X[:-1], Y[:-1]
Xtest_val, Ytest_val = X[-1:], Y[-1:]