LSTM-related Python code __python

Source: Internet
Author: User

1. I first on the source code

The following code is written by a person lstm input data processing:

def load_data (filename, Seq_len, Normalise_window):
    f = open (filename, ' RB '). Read ()
    data = F.split (' \ n ')

    Sequence_length = seq_len + 1 result
    = [] for
    index in range (LEN (data)-Sequence_length):
        result.append (data [Index:index + sequence_length])
    
    If Normalise_window: Result
        = normalise_windows [result] result

    = Np.array (result)

    row = round (0.9 * Result.shape[0])
    train = Result[:row,:
    np.random.shuffle (train)
    X_train = train[:,: -1]
    Y_ Train = train[:,-1]
    x_test = Result[row:,: -1]
    y_test = Result[row:,-1]

    X_train = Np.reshape (X_train, (x_ Train.shape[0], x_train.shape[1], 1)
    x_test = Np.reshape (X_test, (x_test.shape[0), x_test.shape[1], 1  

    ) return [X_train, Y_train, X_test, Y_test]

No further, take a step in the data

For example, the source data is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Then I agreed that the step size is 3, then the data obtained is [1,2,3], [2,3,4], ..., [13,14,15]

2. Code interpretation

X_train = train[:,:-1]


This code indicates that every row in the train is removed, but for the column, the last column is not taken

GitHub Source: Lstm_learn

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.