MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / tf_idf

Function tf_idf

machine_learning/word_frequency_functions.py:123–137  ·  view source on GitHub ↗

Combine the term frequency and inverse document frequency functions to calculate the originality of a term. This 'originality' is calculated by multiplying the term frequency and the inverse document frequency : tf-idf = TF * IDF @params : tf, the term frequency, and idf

(tf: int, idf: int)

Source from the content-addressed store, hash-verified

121
122
123def tf_idf(tf: int, idf: int) -> float:
124 """
125 Combine the term frequency
126 and inverse document frequency functions to
127 calculate the originality of a term. This
128 'originality' is calculated by multiplying
129 the term frequency and the inverse document
130 frequency : tf-idf = TF * IDF
131 @params : tf, the term frequency, and idf, the inverse document
132 frequency
133 @examples :
134 >>> tf_idf(2, 0.477)
135 0.954
136 """
137 return round(tf * idf, 3)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected