Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Have collected the data and organized it like this:

One observation is organized into one dataframe

One dataframe is made up of 100 rows, in sequential order.

One row has 6 features and 1 label

How would I reshape this for a LSTM model... ?

my observation
            idx     prod   period   qty      label      
    0   Customer10  FG1    2483  200.000000   'A'   
    1   Customer11  FG2    2484  220.000000   'B'   
    2   Customer12  FG3    2485  240.000000   'C'
    3   Customer13  FG1    2485  240.000000   'C'
    ...
    100 Customer99  FG1    2485  240.000000   'A'
question from:https://stackoverflow.com/questions/65651282/dataframe-reshape-for-input-into-a-lstm-model

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
351 views
Welcome To Ask or Share your Answers For Others

1 Answer

The first step would be to separate the data frame into x and y variables.

You can do this with a simple for loop, I don't know the specific data format so I can only give a boilerplate-like example.

x = []
y = []

for i in dataframe:
    if Is_Label:
        y.append(i)
    else:
        x.append(i)

Next you would need to convert the arrays into a numpy array. With numpy imported as np you would do.

x = np.array(x)
y = np.array(y)

With numpy you can use the .reshape method to reshape the data into your needs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...