MCPcopy Index your code
hub / github.com/clips/pattern / tf_idf

Function tf_idf

pattern/vector/__init__.py:703–716  ·  view source on GitHub ↗

Calculates tf * idf on the vector feature weights (in-place).

(vectors=[], base=2.71828)

Source from the content-addressed store, hash-verified

701cos = cosine_similarity
702
703def tf_idf(vectors=[], base=2.71828): # Euler's number
704 """ Calculates tf * idf on the vector feature weights (in-place).
705 """
706 df = {}
707 for v in vectors:
708 for f in v:
709 if v[f] != 0:
710 df[f] = df[f] + 1 if f in df else 1.0
711 n = len(vectors)
712 s = dict.__setitem__
713 for v in vectors:
714 for f in v: # Modified in-place.
715 s(v, f, v[f] * (log(n / df[f], base)))
716 return vectors
717
718tfidf = tf_idf
719

Callers

nothing calls this directly

Calls 2

lenFunction · 0.85
sFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…