TF-IDF (Term Frequency-Inverse Document Frequency)
TF-IDF is a statistical measure that assesses the importance of a word within a document relative to a set of documents, often referred to as a corpus. It is widely used in information retrieval, natural language processing, and text mining.
The measure comprises two components: Term Frequency (TF) and Inverse Document Frequency (IDF). Term Frequency calculates how frequently a term appears in a specific document. The intuition is that the more times a word appears in a document, the more relevant it is to the content of that document. Mathematically, it is expressed as:
TF(t, d) = (Number of times term t appears in document d) / (Total number of terms in document d)
On the other hand, Inverse Document Frequency quantifies how much information a word provides, based on how common or rare it is across all documents. Words that are very common across many documents (like ‘the’ or ‘and’) are less informative. IDF is calculated as:
IDF(t, D) = log(Total number of documents in D / Number of documents containing term t)
Combining these two components, the TF-IDF score is calculated as:
TF-IDF(t, d, D) = TF(t, d) * IDF(t, D)
This score helps highlight keywords that are both relevant to a specific document and not overly common in the broader corpus, thus making it a powerful tool for text analysis, search engines, and recommendation systems. For example, documents that contain a high TF-IDF score for a particular term are likely to be more relevant to queries involving that term.