Tfidf(词频-反转文档频率)
TF代表统计部分, 而IDF把权重折扣考虑了进去。
>>> import scipy as sp
>>> def tfidf(term, doc, docset):
··· tf = float(doc.count(term) / sum(doc.count(term) for doc in docset)
··· idf = math.log(float(len(docset)) / (len([doc for doc in docset
if term in doc]))
··· return tf * idf