AI & Machine Learning · reviewed in August 2026
Classification
Classification is a machine learning task where the model predicts which of a fixed set of categories (classes) an observation belongs to — for example, whether an email is spam or not, or which category a product belongs to. It differs from regression in that the output is discrete, not a continuous number.
from sklearn.linear_model import LogisticRegression model = LogisticRegression() model.fit(X_train, y_train) predictions = model.predict(X_test)
Frequently asked questions
What is binary versus multiclass classification?
Binary distinguishes between just two classes (spam / not spam); multiclass distinguishes between three or more mutually exclusive classes (for example, a flower's species among several).
How do you measure how good a classifier is?
With metrics like accuracy, precision, recall, and F1 — accuracy alone can be misleading when classes are very imbalanced, which is why it's usually paired with precision and recall.
What algorithms are commonly used for classification?
Logistic regression, decision trees and random forests, support vector machines (SVM), and neural networks — the choice depends on the data size, the interpretability required, and the pattern's complexity.