2
$\begingroup$

I have data csv file with three inputs names temperature, humidity, wind. Here I want to predict temperature value in every 60 minute using LSTM model.

Here I write the code to reshape the train . But I got an error tuple' object is not callable

My code:

data = pd.read_csv('data6.csv' )
data['date'] = pd.to_datetime(data['date'] + " " + data['time'], format='%m/%d/%Y %H:%M:%S')
data.set_index('date', inplace=True)
data = data.values

scaler = MinMaxScaler(feature_range=(0, 1))
data = scaler.fit_transform(data)

train_size = int(len(data) * 0.67)
test_size = len(data) - train_size
train, test = data[0:train_size,:], data[train_size:len(data),:]

X = 1
n_out = 1

x,y=[],[]
start =0
data = train.reshape(train.shape(train.shape[0] ,3, train.shape[1]))
for _ in range(len(data)):
  in_end = start+X
  out_end= in_end + n_out
  if out_end < len(data):
    x_input = data[start:in_end]
    x.append(x_input)
    y.append(data[in_end:out_end,0])
start +=1

x = np.asanyarray(x)
y = np.asanyarray(y)

My csv file

Error:

data = train.reshape(train.shape(train.shape[0] ,3, train.shape1))

Error image: enter image description here

Can anyone help me to solve this problem?

Error:

enter image description here

$\endgroup$
  • $\begingroup$ Would you mind putting the error content, not the image? There are people who can't see the image content and your chance for finding a solution can be diminished. $\endgroup$ – Media Jul 11 '19 at 9:10
  • $\begingroup$ Please, also provide the line from which you get the error. By the way, the error comes from the last line, namely data = train.reshape(train.shape(train.shape[0] ,3, train.shape[1])) where you've tried to call shape as a method while it is a tuple and you may want to use indexing operator, [index] instead of calling shape as a method. $\endgroup$ – Media Jul 11 '19 at 9:17
  • $\begingroup$ @Vaalizaadeh Thank you for the fast reply. I understood what you are saying and here I editted my question and here what I am trying to do is x values are my inputs and y value is my output (temperature) y (t+1) . For that I wrote the code. I hope now you can understand my question. $\endgroup$ – bala Jul 11 '19 at 9:34
  • $\begingroup$ @Vaalizaadeh I used the index operator also $\endgroup$ – bala Jul 11 '19 at 9:36
  • 1
    $\begingroup$ @Vaalizaadeh I tried it and gave ma an error. Then I tried your earlier methods and also the code that is providing by my friend and I tried again and again. Then I found the correct code for my code. Thank you for helping me to solve this problem. Here I upoad the code below. $\endgroup$ – bala Jul 11 '19 at 15:25
3
$\begingroup$

The problem is that train.shape is simply a tuple. So train.shape(arguments) doesn't make sense because train.shape is not callable (hence the error). Try to just replace that line by

data = train.reshape((train.shape[0], 3, train.shape[1]))
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you for the fast reply. I applied your code and it gave me this error " cannot reshape array of size 402 into shape (134,3,3)" here I paste the image of the error. $\endgroup$ – bala Jul 11 '19 at 14:20
  • $\begingroup$ @bala I do not know the dimensions of your array train, and I don’t know to what you want to rescale them. I thought that your array train has the shape shape[0]xshape[1]x3, but that is not the case. You have to think of the compatible shape that you want (I can‘t do that for you because I don‘t know enough about the shape of train). $\endgroup$ – Maximilian Janisch Jul 11 '19 at 14:25
  • $\begingroup$ Ya I got it. Thank you for the reply. $\endgroup$ – bala Jul 11 '19 at 14:27
  • $\begingroup$ @bala You‘re welcome! I‘m glad to have helped. $\endgroup$ – Maximilian Janisch Jul 11 '19 at 14:28
  • $\begingroup$ By using your code and trying another method I found the correct code which is running . Noe my full code is working. I upload my code below. Once again thank you for helping me. $\endgroup$ – bala Jul 11 '19 at 15:20
1
$\begingroup$

After Trying all the codes by providing my friends , I found the correct code for my code. Here I upload the code . Thank you for helping me to solve my code.

data = train.reshape((train.shape[0], 1, train.shape[1]))
|improve this answer|||||
$\endgroup$

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.