Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

10. Finding Independent Features > Displaying the Results

Displaying the Results

Exactly how you view the results is a little complicated. Every feature in the features matrix has a weighting that indicates how strongly each word applies to that feature, so you can try displaying the top five or ten words in each feature to see what the most important words are in that feature. The equivalent column in the weights matrix tells you how much this particular feature applies to each of the articles, so it’s also interesting to show the top three articles and see how strongly this feature applies to all of them.

Add a new function called showfeatures to

from numpy import *
def showfeatures(w,h,titles,wordvec,out='features.txt'):
  toppatterns=[[] for i in range(len(titles))]

  # Loop over all the features
  for i in range(pc):
    # Create a list of words and their weights
    for j in range(wc):
    # Reverse sort the word list
    slist.sort(  )
    slist.reverse(  )

    # Print the first six elements
    n=[s[1] for s in slist[0:6]]

    # Create a list of articles for this feature
    for j in range(len(titles)):
      # Add the article with its weight


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free 10-Day Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint