0
$\begingroup$

I have a dataset with four input. here I am trying to predict X1 input in next time period using lstm model.

Here I put x_train 80% and x_test 20% . In x_test first input some of rows are with 0 values.

What I want is I want to read that 0 value separately. I tried and it didn't work for me. Can anyone help me to solve this problem. Here my code:

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 : ,]
y_train=y[0: train_end]
y_test=y[train_end :] 
x_train=x_train.reshape(x_train.shape +(1,))
x_test=x_test.reshape(x_test.shape + (1,))

After writing code for lstm I tried to predict value for x_test. Before that I want to specify that rows with 0 values.

x_test_n = np.flip(x_test_n, axis=0)
curr_frame = x_test_n[0]

Then it just read first row with four input together. What I want is to read first input with 0 values.

Image for what I got:

enter image description here

What I want to read

enter image description here

After changing the code:

pred=[]
for index, row in x_test_n.iterrows():
  if index_row, index_col = np.where(x_test_n == 0)
    x_test_n.iloc[index] = pred[-1]
    row['X_test_n'] = pred[-1]
    pred1 = model.predict(x_test_n)
    pred.append(pred1)

It gave me an error:

if index_row, index_col = np.where(x_test_n == 0)

$\endgroup$
0
$\begingroup$

For a 2D np array x_test_n, you could use index_row, index_col = np.where(x_test_n == 0) to return the indices with 0 values.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ @Hassan Thank you for the fast reply. I used your code and wrote the code for it and it gave me an error : invalid syntax $\endgroup$ – team Jul 25 '19 at 15:00
  • $\begingroup$ np.where gives you the indices where a certain value is, not True or False for if statements. $\endgroup$ – Hassaan Jul 25 '19 at 18:32
  • $\begingroup$ When I used your code it gave me this error "too many values to unpack (expected 2)" $\endgroup$ – team Jul 26 '19 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.