简体   繁体   中英

'numpy.ndarray' object has no attribute 'drop'

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:

在此处输入图片说明

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?

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.

X_train 是一个数组而不是一个数据框您需要知道要删除的列的位置

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM