-2

I am trying to predict the future value with three inputs. Here I want to forecast the future value according to the three inputs in every one hour. Here g= temperature, p=humidity, c=wind and I want to predict temperature in next hour according to these inputs. That's why here I put n_out is 1, I wrote the code in def class. After that I tried to add that def class value as x,y value. Because I am going to write it as train and test value. But the error came as this. I am going to predict future value using LSTM . After this I don't know how to add this code as train and test into LSTM model. Can anyone help me to solve this problem? Here I paste my code and csv file.

def change(train,X, n_out=1):
    data = train.reshape((train.shape[0]))
    x, y = list(), list()
    in_start = 0
    # step over the entire history one time step at a time
    for _ in range(len(data)):
        # define the end of the input sequence
        in_end = in_start + X
        out_end = in_end + n_out
        # ensure we have enough data for this instance
        if out_end < len(data):
            x_input = data[in_start:in_end, 0]
            x_input = x_input.reshape((len(x_input), 3))
            x.append(x_input)
            y.append(data[in_end:out_end, 0])
        # move along one time step
        in_start += 1
    return array(x), array(y)


data= pd.DataFrame(data,columns=['g','p','c']) 
data.columns = ['g', 'p', 'c',]
pd.options.display.float_format = '{:,.0f}'.format
data = data.dropna ()
cols=['g', 'p', 'c']
X=data[cols]
x,y = change(data)

The error came as

enter image description here

my csv file:

enter image description here

Aftre edditing the code it gave me this error:

enter image description here

10
  • Please post text as text, not pictures. And make your code match the error messages. Anyway what do you not understand about 'DataFrame' object has no attribute 'reshape' exactly? Jun 17, 2019 at 10:11
  • Furthermore, what are you trying to achieve with train.reshape((train.shape[0]))? It does not make any sense to me. Jun 17, 2019 at 10:14
  • @Goyo LSTM() layer must specify the shape of the input. ... array of data when fitting the model and when making predictions, ... We can then use the reshape() function . That's why I tried to reshape the data value.
    – user10270654
    Jun 17, 2019 at 10:52
  • I do not see how that answers any of the questions I asked you. Did you understand my questions? BTW the first one is probably more important. Jun 17, 2019 at 11:01
  • @Goyo for the first question Does panda.dataframe is builtup reshape? if it is should I have to change my code with values?
    – user10270654
    Jun 17, 2019 at 14:31

1 Answer 1

2

In your definition of the function you have 3 parameters: train, X and n_out=1

def change(train, X, n_out=1)

when you are calling your function you are providing just 1 argument(data)

x,y = change(data)

how n_out you define as 1, you need to provide x also, or define your function as:

def change(train, n_out=1)

NOTE:

you need to provide X when you are calling your function for example :

x,y = change(data, 1) 

or define functrion like :

def change(train, X=1, n_out=1)
7
  • i want to predict one value according to these three inputs. Okay if I remove this x,y=change(data) , then how I can add this into the train model to predict value using LSTM. Do you have any idea for this? If I removed then how I can write the input data in code.
    – user10270654
    Jun 17, 2019 at 8:59
  • you need to provide X when you are calling your function for example : x,y = change(data, 1) , or definet it for example like : def change(train, X=1, n_out=1)
    – ncica
    Jun 17, 2019 at 9:04
  • Yes I tried this method then it gave me long error. After tried your method the error is showing (reshape)
    – user10270654
    Jun 17, 2019 at 9:07
  • can you provide what is your data here: pd.DataFrame(data,columns=['g','p','c'])
    – ncica
    Jun 17, 2019 at 9:13
  • g= temeprature ,p=humidity ,c = wind According to these inputs I want to predict temperature in next hour
    – user10270654
    Jun 17, 2019 at 9:23

Your Answer

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