Probabilistic and margin classifiers.
Meet Naive Bayes and support vector machines without treating their names as magic.
Start with the meaning.
Naive Bayes and support vector machines are different ways to classify examples. Naive Bayes combines evidence from features using conditional probabilities and a simplifying assumption that features behave independently given the class. That assumption is often false, but the model can still classify well, especially for sparse word counts. The point is not that words truly occur independently; the assumption makes estimation simple with limited data.
A support vector machine, or SVM, looks for a boundary that separates classes with a wide margin when possible. The margin is the space between the boundary and nearby training points. Points closest to that boundary are especially influential; they are the support vectors. A soft-margin SVM permits some violations because real data rarely separates perfectly. Its regularisation choice controls the tradeoff between a wide margin and fitting training examples closely.
How the idea works.
Naive Bayes comes in variants suited to different feature meanings. Multinomial Naive Bayes is commonly used with nonnegative counts such as how often words appear; Bernoulli Naive Bayes models binary occurrence; Gaussian Naive Bayes uses a bell-curve assumption for numeric features. Choosing a variant that disagrees with the feature representation can make the model meaningless even when fit accepts the array.
A linear SVM uses a straight boundary in the supplied feature space. Kernel SVMs can represent nonlinear boundaries by comparing examples through a kernel function. An RBF kernel is common, but its distance-based notion of similarity makes feature scaling important. The C and gamma hyperparameters influence boundary flexibility. A high-dimensional kernel model can become expensive, and its score or decision function is not automatically a calibrated probability.
These models illustrate a broader lesson: every algorithm makes assumptions. Naive Bayes assumes a probability structure; an SVM assumes a useful margin in the chosen representation. Model selection is not about declaring a universal winner. It is about matching assumptions, data size, feature type, computational cost, and evaluation evidence to a particular task.
Follow the code.
from sklearn.naive_bayes import MultinomialNB
X = [[2, 0], [3, 0], [0, 2], [0, 3]]
y = ["sports", "sports", "finance", "finance"]
model = MultinomialNB()
model.fit(X, y)
print(model.predict([[1, 0]]))Each row has two nonnegative feature counts. Imagine the first count represents a sports word and the second a finance word. The first two examples have the sports count; the next two have the finance count. fit estimates class and feature probabilities from these labelled rows. The new row [[1, 0]] contains the first feature and is predicted as sports. The result is an array containing one label.
The example is intentionally tiny. Real text vectorisation creates many columns and must be fitted on training documents only. A word's absence, frequency, and the class prevalence all influence the model's calculation. The predicted class is not proof that the model understands a document's subject.
What the result does not say.
A support vector classifier would be a different candidate for the same feature table. Its behavior would depend on scaling and the chosen kernel. This chapter keeps the code example to one model so its data flow is readable.
Probabilities output by different classifier families are not equally reliable. A model may rank cases well while giving poor probability estimates. If a decision needs probability, calibration must be evaluated separately.
One clear idea.
Naive Bayes estimates a simplified probability model; SVMs seek a separating margin in a chosen feature space.
The ML cookbook
Complete, explained Python workflows sit alongside this reading course.