Counting words treats "the" and "thrombosis" as equally informative. TF-IDF fixes that by multiplying how often a term appears in a document by how rare it is across the collection.
Use exactly these definitions:
1tf(t, d) = count of t in d / number of tokens in d2idf(t) = ln(N / df(t)) N = number of documents3 df(t) = documents containing t4value = tf(t, d) * idf(t)
Task: write tfidf(documents), where each document is a list of tokens. Return one vector per document, rounded to 4 decimal places.
+1 anywhere, and no vector normalization — stick to the formulas above.A term appearing in every document gets
ln(N/N) = 0and its whole column vanishes. That's the mechanism doing the real work: stopwords aren't removed by a list, they're mathematically zeroed out for being everywhere.