ML Models & Algorithms
Naive Bayes
In shortNaive Bayes is a fast, probability-based classifier that assumes features are independent, often used for text tasks such as spam and intent labelling.
Naive Bayes is a family of classification algorithms that use probabilities to decide which category an item belongs to. MLforSEO’s classification lesson describes it as fast and efficient, and also quite surface-level: it assumes every feature is independent of the others (the “naive” part), which keeps the maths simple but limits how well it handles complex problems. It is a classic baseline for text classification.
How it works
The model is based on Bayes’ theorem. During training on labelled examples (supervised learning), it counts how often each word or feature appears in each class. To classify a new item, it multiplies the probabilities of its features for every class and picks the class with the highest score.
The naive assumption is that words do not influence each other: “cheap” and “flights” are treated as separate clues even though they clearly belong together. Text is usually turned into a bag of words or TF-IDF representation first. scikit-learn offers several variants:
- Multinomial: works on word counts, one of the two classic text variants (TF-IDF vectors are also known to work well).
- Bernoulli: works on whether a word is present or absent, and may do better on short documents.
- Complement: adapted for imbalanced classes and often stronger than Multinomial on text.
- Gaussian: for continuous numeric features.
How it’s used in SEO and marketing
- Spam and moderation: the textbook use case, filtering spam comments, form submissions or reviews.
- Search intent classification: words such as buy, price or near me push a query towards transactional, how and what towards informational.
- Tagging support tickets, reviews or social posts into themes when you have a labelled sample.
- A quick baseline to beat before trying logistic regression, a support vector machine or a transformer model.
Example
You label 500 keywords as informational or transactional and train a Multinomial Naive Bayes model on their word counts. The word “buy” appears mostly in transactional examples and “guide” mostly in informational ones. For the new keyword “buy trail running shoes guide”, the model weighs both clues, along with every other word, and returns the more probable class. Checking it on a held-out labelled set with a confusion matrix shows where it struggles, usually on mixed or very short queries.
Limitations and things to watch
- The independence assumption ignores word order and context, so negation (“not cheap”) and phrases trip it up.
- Its probability scores are poorly calibrated. scikit-learn’s documentation calls it a decent classifier but a bad estimator, so do not read its probabilities as confidence.
- Words never seen in training need smoothing, otherwise they zero out a class.
- For nuanced language, embedding-based or transformer classifiers usually perform better; Naive Bayes earns its place through speed and small data needs.
Learn it on MLforSEO
Where Naive Bayes shows up on MLforSEO
Learn it in a course
Sources and further reading
Other terms from ML Models & Algorithms
- BERT (Bidirectional Encoder Representations from Transformers)Google's 2018 transformer language model that reads text in both directions to produce context-aware embedding…
- BERTopicA modular topic modelling technique that clusters transformer embeddings and labels each cluster with class-ba…
- BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies)BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies) clusters very large numeric datasets by s…
- BM25A classic ranking function that scores documents by how often query words appear, adjusted for word rarity and…
- Boyer-MooreA fast exact string-search algorithm that compares a pattern from right to left and skips ahead after mismatch…
- c-TF-IDFClass-based TF-IDF: treats each cluster as one document to find the words that best describe it, used by BERTo…
- Centroid-based ClusteringA clustering family that groups data around central points (centroids), each the average of its cluster's memb…
- Convolutional Neural Network (CNN)A deep learning architecture that scans data with small learned filters to detect local patterns; the classic…
- DBSCANDensity-based clustering that groups closely packed points, finds the number of clusters itself and labels iso…