2
votes

I have a dataset with four inputs named X1, X2, X3, X4. Here I created the lstm model to predict next X1 value with the previous values of four inputs.

Here I changed the time into minutes and then I set the time as index.

Then I created the x_train, x_test , y_test and y_train. Then I wanted to drop the time in x_train and x_test.

I used the code:

data= pd.DataFrame(data,columns=['X1','X2','X3','X4'])
pd.options.display.float_format = '{:,.0f}'.format
print(data)

data:

enter image description here

y=data['X1'].astype(int)
cols=['X1', 'X2', 'X3','X4']
x=data[cols].astype(int)

data=data.values
scaler_x = preprocessing.MinMaxScaler(feature_range =(0, 1))
x = np.array(x).reshape ((len(x),4 ))
x = scaler_x.fit_transform(x)
scaler_y = preprocessing.MinMaxScaler(feature_range =(0, 1))
y = np.array(y).reshape ((len(y), 1))
y = scaler_y.fit_transform(y)

train_end = 80
x_train=x[0: train_end ,]
x_test=x[train_end +1: ,]
y_train=y[0: train_end]
y_test=y[train_end +1:] 
x_train=x_train.reshape(x_train.shape +(1,))
x_test=x_test.reshape(x_test.shape + (1,))

x_train = x_train.drop('time', axis=1)
x_test = x_test.drop('time', axis=1)

Then error :'numpy.ndarray' object has no attribute 'drop'

Can any one help me to solve this error?

2
Please show us how you loaded in your dataset as well as the first few rows of your training and test. You're assuming it's a pandas dataframe but it's a numpy array. - rayryeng
@rayryeng Yes I edited my question. I hope now you can understand my code - team

2 Answers

1
votes

Because you extracted the values of your Pandas dataframe, your data have been converted into a NumPy array and thus the column names have been removed. The time column is the first column of your data, so all you really need to do is index into it so that you extract the second column and onwards:

x_time_train = x_train[:, 0]
x_train = x_train[:, 1:]
x_time_test = x_test[:, 0]
x_test = x_test[:, 1:]

Take note that I've separated the time values for both training and testing datasets as you require them for plotting.

0
votes

X_train is an array not a dataframe You need to know the position of the column to drop

  np.delete(X_train, [index_to_drop], 1)