Introduction to Machine Learning for SEO
- Practical: Clustering of page content with BERTopic
- Practical: Query Entity Extraction with Google NLP and Entity ML-enabled data analysis
ML Models & Algorithms
In shortA weighting that scores how important a word is to one document compared with a whole collection, so distinctive words count more than common ones.
TF-IDF (term frequency-inverse document frequency) is a way of weighting words so that the ones that make a document distinctive count the most. A word scores highly when it appears often in one document but rarely across the rest of the collection. It is one of the most widely used techniques for turning text into numbers, a step known as feature extraction.
The weight is the product of two parts:
Words that appear everywhere, such as “the” or a term every page in your niche uses, get a low IDF and therefore low weight. Each document becomes a vector of TF-IDF weights, usually normalised so documents of different lengths can be compared, often with cosine similarity. Libraries such as scikit-learn’s TfidfVectorizer apply small smoothing tweaks to the formula, so check the defaults.
TF-IDF works on n-grams too. On character n-grams it powers fast fuzzy matching, and BERTopic’s class-based TF-IDF treats each cluster as one big document to find the words that describe each topic.
In a dataset of finance entities, “loan” and “credit” appear in many names, so TF-IDF gives them low weight. “Crowdfunding” appears in only a few, so it gets a high weight. When the entities are clustered, specialised concepts stand apart instead of everything collapsing into one large “loans and credit” group.