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

Finding the most similar documents

The CountVectorizer result lets us find the most similar documents using the pdist() function for pairwise distances provided by the scipy.spatial.distance module. It returns a condensed distance matrix with entries corresponding to the upper triangle of a square matrix. We use np.triu_indices() to translate the index that minimizes the distance to the row and column indices that in turn correspond to the closest token vectors:

m = binary_dtm.todense() # pdist does not accept sparse formatpairwise_distances = pdist(m, metric='cosine')closest = np.argmin(pairwise_distances) # index that minimizes distancerows, cols = np.triu_indices(n_docs) # get row-col indicesrows[closest], cols[closest](11, 75)

Articles ...

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