Created
May 25, 2015 20:14
-
-
Save davidrichards/2c76663ec75d6b55a813 to your computer and use it in GitHub Desktop.
Term Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
from urllib import urlopen | |
import textmining | |
urls = [ | |
'http://www.webmd.com/cancer/childhood-leukemia-symptoms-treatments', | |
'http://kidshealth.org/parent/medical/cancer/cancer_leukemia.html', | |
'http://www.nlm.nih.gov/medlineplus/childhoodleukemia.html' | |
] | |
matrix = textmining.TermDocumentMatrix() | |
def add_document(m, url): | |
html = urlopen(url).read() | |
soup = BeautifulSoup(html) | |
text = soup.get_text() | |
m.add_doc(text) | |
return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas | |
terms = pandas.read_csv('matrix.csv') | |
data = terms.values | |
U, s, V = np.linalg.svd(data.T) | |
S = np.diag(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment