2

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. Commented Aug 2, 2019 at 6:24
  • @rayryeng Yes I edited my question. I hope now you can understand my code Commented Aug 2, 2019 at 6:27

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Ya I got it what you are saying. Thank you for the reply. So If I want to plot predicted value and actual value after training the model, then how to apply time as x axis, Because I applied with the time to plot my graph and it didn't display nothing in x axis.
@team Easy. Extract the time variable between both: x_time_train = x_train[:, 0]; x_time_test = x_test[:, 0]. You have two separate arrays that contain the time intervals for both datasets which you can now use for plotting.
Thank you very much, this is really helpful to me.
@team No problem at all! I've updated my answer so you can keep the time variables separate before you overwrite your datasets so they no longer have the time values. Good luck!
@ rayryeng I have another problem, like if I put "data.set_index('time', inplace=True)" Then trying to write x_train and x_test,. After training the model ,plotting predict and actual value with time. Then Can I use that time for x axis? If you are okay to reply this question, it will be more helpful to me?
|
0

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)

4 Comments

Okay then how can I drop the time in x_train. , I tried so many method. If you know any solution can you post it?
Your answer is not helpful. Please provide a way to resolve the problem.
@Benoit de Menthière Thank you for the response, But this is not the answer what I am looking forward and this is not the correct answer.
What are you looking for, i explain you how to drop a column in a np.array, as your X_train is an array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.