Skip to Content
Hands-On Machine Learning for Algorithmic Trading
book

Hands-On Machine Learning for Algorithmic Trading

by Stefan Jansen
December 2018
Beginner to intermediate
684 pages
21h 9m
English
Packt Publishing
Content preview from Hands-On Machine Learning for Algorithmic Trading

Preprocessing the text data

We are going to load the IMDB dataset from the source to manually preprocess (see notebook).

Keras provides a tokenizer that we use to convert the text documents to integer-encoded sequences, as shown here:

num_words = 10000t = Tokenizer(num_words=num_words,              lower=True,              oov_token=2)t.fit_on_texts(train_data.review)vocab_size = len(t.word_index) + 1train_data_encoded = t.texts_to_sequences(train_data.review)test_data_encoded = t.texts_to_sequences(test_data.review)

We also use the pad_sequences function to convert the list of lists (of unequal length) to stacked sets of padded and truncated arrays for both the train and test datasets:

max_length = 100X_train_padded = pad_sequences(train_data_encoded,  maxlen=max_length, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Machine Learning for Algorithmic Trading - Second Edition

Machine Learning for Algorithmic Trading - Second Edition

Stefan Jansen

Publisher Resources

ISBN: 9781789346411Supplemental Content