1 Definition and basic concepts
Classification is a supervised learning task in which a model assigns each input instance to one of a set of predefined categories. The categories may represent labels such as “spam” and “not spam,” “disease” and “no disease,” or named object classes in an image. The central aim is to learn patterns from examples whose correct labels are known, then apply those patterns to new cases.
In practice, classification combines statistical inference, feature engineering, and prediction. A successful classifier does not merely memorize training examples; it identifies regularities that generalize to unseen data. This makes classification one of the most widely used methods in machine learning.
1.1 Supervised learning setting
In supervised learning, each training example consists of an input and its corresponding target output. For classification, the target is a category rather than a continuous value. The learner uses these labeled examples to estimate a function that maps inputs to classes.
The quality of the learned model depends strongly on the representativeness of the training data. If the labeled sample differs from the real-world cases the model will later encounter, performance often declines. Because of this, classification systems are usually evaluated on separate data not used during fitting.
1.2 Categorical target variables
A categorical target variable takes values from a finite set of classes. These classes may be nominal, meaning they have no inherent order, or ordinal, meaning they follow a rank. The choice of modeling approach and evaluation method can depend on this structure.
Classification differs from regression in that the output is discrete. A classifier may still estimate probabilities for each class, but its final decision is a category label. In many applications, these probabilities are as important as the predicted class itself.
1.3 Input features and labels
Input features are the measurable attributes used to make the prediction. They may include numerical measurements, text-derived counts, pixel intensities, or encoded categories. The label is the correct class assigned to each training instance.
Feature quality often determines the usefulness of the model. Two datasets with the same labels can yield very different results depending on whether the input variables capture meaningful information about the task. In many projects, a large part of the work involves preparing features that are informative, consistent, and appropriately scaled.
1.4 Decision boundaries
A decision boundary is the region in feature space where the predicted class changes from one label to another. For simple models, these boundaries may be linear or easy to visualize. For more complex models, they can be highly irregular.
Decision boundaries illustrate how a classifier separates categories. A boundary that is too simple may miss important structure, while one that is too complex may fit noise rather than genuine patterns. Balancing these concerns is a key part of model design.
2 Types of classification problems
Classification tasks differ according to the number and structure of the possible labels. Some involve only two outcomes, while others require assigning several labels at once or respecting an ordering among classes. These distinctions affect both modeling choices and evaluation.
2.1 Binary classification
Binary classification involves exactly two classes. Examples include yes/no decisions, positive/negative test results, and fraudulent/non-fraudulent transactions. Because the outcome space is small, binary problems are often the simplest classification setting.
Many algorithms naturally produce a score or probability for the positive class. A threshold is then used to convert that score into a binary decision. This makes binary classification especially sensitive to threshold selection and class imbalance.
2.2 Multiclass classification
Multiclass classification assigns each instance to one of three or more mutually exclusive categories. Typical examples include handwriting recognition, species identification, and topic classification. Only one label is selected for each case.
Multiclass tasks are often handled either directly or by decomposing them into multiple binary problems. The difficulty usually increases as the number of classes grows, especially when some categories are similar to one another or are underrepresented in the data.
2.3 Multilabel classification
In multilabel classification, an instance may belong to several classes simultaneously. A document, for example, can be tagged with more than one topic, or an image can contain several object types. Each label is treated as an independent yes/no decision, although dependencies may also be modeled.
This setting differs from multiclass classification because the labels are not mutually exclusive. Evaluation often requires metrics that account for partial correctness, since predicting some but not all relevant labels can still be useful.
2.4 Ordinal classification
Ordinal classification involves categories with a natural order, such as mild, moderate, and severe. The labels are discrete, but the ranking matters. Treating such tasks as ordinary multiclass problems can ignore useful structure.
Methods for ordinal classification aim to preserve the ordering in the predictions. This is particularly important when errors between adjacent categories are less serious than errors between distant ones.
3 Data preparation
Data preparation is a crucial stage in classification because most algorithms assume that the inputs are well structured and informative. Raw data often contain irrelevant variables, inconsistent formats, missing entries, and categories that must be transformed before modeling. Careful preparation can improve both accuracy and stability.
3.1 Feature selection
Feature selection is the process of choosing a subset of relevant variables from a larger set. The goal is to remove redundant or noisy inputs that do not contribute meaningful predictive value. This can reduce overfitting, speed up training, and improve interpretability.
Selection methods may rely on statistical tests, model-based importance measures, or simple filtering rules. In some cases, a smaller set of well-chosen features performs better than a very large feature collection.
3.2 Feature extraction
Feature extraction transforms raw data into a new representation that may be more suitable for classification. Text may be converted into word counts or embeddings, images into numerical descriptors, and audio into spectral features. The extracted variables often capture structure that is not obvious in the original form.
Unlike feature selection, which keeps existing variables, feature extraction creates new ones. It is especially useful when the raw input is high-dimensional or unstructured.
3.3 Data cleaning
Data cleaning addresses errors, inconsistencies, duplicates, and outliers. Classification models can be sensitive to corrupted records, mismatched formats, or mislabeled examples. Cleaning aims to improve the reliability of the training set.
Typical steps include correcting invalid values, standardizing units, resolving duplicate entries, and checking label quality. Although cleaning may seem routine, it often has a strong effect on downstream performance.
3.4 Encoding categorical variables
Many models require numerical inputs, so categorical variables must be encoded in a machine-readable form. Common approaches include one-hot encoding, ordinal encoding, and target-based representations. The best choice depends on the algorithm and on whether the categories have a natural order.
Improper encoding can distort relationships or introduce unintended ranking effects. For that reason, preprocessing choices should be matched carefully to the model and task.
3.5 Handling missing values
Missing values appear when some measurements are unavailable or not recorded. Classification methods differ in how they treat incomplete data, and many require explicit handling before training. Common strategies include deletion, simple imputation, or model-based estimation.
The chosen approach depends on how much data is missing and whether the absence itself carries information. In some domains, missingness may reflect a meaningful process rather than a random gap.
4 Common classification algorithms
A wide range of algorithms can be used for classification, from simple probabilistic methods to flexible nonlinear models. Each has strengths and limitations in terms of speed, interpretability, and performance on different kinds of data. Selection often depends on dataset size, feature type, and the need for transparency.
4.1 Logistic regression
Logistic regression is a widely used statistical classifier for binary problems and, with extensions, for multiclass tasks. It estimates the probability of a class using a linear combination of input features passed through a sigmoid or related function. Despite its name, it is a classification method rather than a regression method.
The model is valued for its simplicity, speed, and interpretability. Coefficients can often be examined to understand how features influence the predicted outcome.
4.2 Naive Bayes classifiers
Naive Bayes classifiers are probabilistic models based on Bayes’ theorem and a strong assumption that features are conditionally independent given the class. Although this assumption is often unrealistic, the method can perform surprisingly well, especially in text classification.
These classifiers are computationally efficient and work well with high-dimensional sparse data. They are commonly used when training speed and baseline performance are important.
4.3 k-nearest neighbors
The k-nearest neighbors method classifies a new instance by looking at the labels of the most similar training examples. Similarity is usually measured by distance in feature space. The predicted class is often determined by majority vote among the nearest neighbors.
This approach is conceptually simple and requires little explicit training. However, it can become slow on large datasets and may be sensitive to scaling, noise, and irrelevant features.
4.4 Decision trees
Decision trees classify data by applying a sequence of tests on the input features. Each internal node represents a decision rule, and each leaf corresponds to a predicted class. The structure is easy to visualize and can be interpreted as a set of if-then statements.
Trees can capture nonlinear relationships and interactions among variables. At the same time, deep trees may overfit unless they are pruned or constrained.
4.5 Random forests
Random forests combine many decision trees trained on different subsamples of the data and feature space. The final prediction is usually based on majority vote or averaged probabilities. This ensemble strategy often improves stability and predictive accuracy.
By reducing the variance of single trees, random forests can handle complex datasets with relatively strong performance. They are often less interpretable than one tree but more robust in practice.
4.6 Support vector machines
Support vector machines aim to find a separating boundary with a large margin between classes. For linearly separable data, the model seeks the hyperplane that maximizes the distance to the nearest points from each class. Kernel methods extend this idea to nonlinear decision boundaries.
SVMs can be effective in high-dimensional settings and are especially useful when the classes are well separated. Their performance depends on kernel choice and parameter tuning.
4.7 Neural networks
Neural networks are flexible models composed of interconnected layers of simple units. They can learn complex nonlinear relationships and are widely used in modern classification systems, especially for images, speech, and text. Deep architectures can represent highly abstract patterns.
These models usually require larger datasets and more careful tuning than simpler methods. Their flexibility can yield strong results, but it can also make interpretation more difficult.
5 Model training
Training involves adjusting model parameters so that predictions match the labeled examples as closely as possible. Because a model can fit the training set too closely or too loosely, training must be paired with validation procedures that estimate generalization performance. This stage also includes controlling complexity and addressing class distribution.
5.1 Training and validation split
A common practice is to divide data into separate training and validation sets. The training set is used to fit the model, while the validation set is used to assess how well it performs on unseen examples during development. This helps detect whether the model is learning useful patterns or merely memorizing.
The split should be representative of the overall data distribution. In time-dependent tasks, the split may need to respect chronological order rather than using random sampling.
5.2 Cross-validation
Cross-validation evaluates a model by repeatedly training and testing it on different partitions of the data. In k-fold cross-validation, the data are divided into several folds, and each fold is used once as a test set. The results are then averaged.
This method provides a more stable estimate of performance than a single split. It is especially helpful when data are limited.
5.3 Hyperparameter tuning
Hyperparameters are settings chosen before or outside the main learning process, such as tree depth, regularization strength, or the number of neighbors. Hyperparameter tuning searches for values that improve validation performance. Common strategies include grid search, random search, and more advanced optimization methods.
Good tuning can significantly affect the final quality of a classifier. Poorly chosen settings may lead to underfitting, overfitting, or inefficient training.
5.4 Regularization
Regularization adds constraints or penalties to reduce model complexity. By discouraging overly large coefficients or overly intricate decision rules, it helps prevent overfitting. Common forms include L1 and L2 penalties.
Regularization is useful when the model has many parameters relative to the amount of data. It often improves generalization even if it slightly lowers training accuracy.
5.5 Class weighting
Class weighting gives different importance to different categories during training. This is useful when some classes are rare and would otherwise be ignored by the learning algorithm. Heavier weights for minority classes can encourage the model to pay more attention to them.
Weighting is one strategy for dealing with imbalanced data. It can be combined with sampling methods and threshold adjustment.
6 Evaluation and performance metrics
Evaluation measures how well a classifier performs on unseen data. Different metrics emphasize different aspects of performance, and no single number is ideal for every task. The most appropriate choice depends on class balance, decision costs, and whether probabilities or labels are more important.
6.1 Accuracy
Accuracy is the proportion of correct predictions among all predictions. It is easy to understand and widely reported. For balanced datasets, it can give a reasonable summary of performance.
However, accuracy can be misleading when classes are highly imbalanced. A model that always predicts the majority class may achieve high accuracy while failing at the actual task.
6.2 Precision and recall
Precision measures the proportion of predicted positives that are truly positive, while recall measures the proportion of actual positives that are correctly identified. These metrics focus on different types of error. Precision reflects how reliable positive predictions are, whereas recall reflects how completely the model finds the positive cases.
The relative importance of precision and recall depends on the application. Some tasks prioritize avoiding false alarms, while others place greater value on missing as few true cases as possible.
6.3 F1 score
The F1 score is the harmonic mean of precision and recall. It provides a single value that balances the two, making it useful when both types of error matter. It is often preferred over accuracy in imbalanced settings.
Because it combines two metrics, the F1 score is especially informative when positive class detection is important. It does not, however, capture all aspects of model quality.
6.4 Confusion matrix
A confusion matrix is a table that compares predicted labels with true labels. It shows counts of correct predictions and different kinds of mistakes. In binary classification, it typically includes true positives, true negatives, false positives, and false negatives.
The matrix gives a more detailed picture than a single summary score. It is useful for diagnosing which classes are being confused with one another.
6.5 ROC curve and AUC
The receiver operating characteristic curve plots the tradeoff between true positive rate and false positive rate across different thresholds. The area under the curve, or AUC, summarizes the curve into a single number. Higher values usually indicate better ranking ability.
ROC analysis is especially useful when the classifier outputs probabilities or scores. It helps assess performance independently of a fixed decision threshold.
6.6 Log loss
Log loss measures the quality of predicted probabilities rather than just the final class label. It penalizes confident wrong predictions more strongly than uncertain ones. This makes it useful when calibrated probability estimates matter.
A model with good classification accuracy may still have poor log loss if its probability estimates are unreliable. For that reason, log loss complements label-based metrics.
7 Practical considerations
Real classification systems must deal with complications beyond the core prediction task. These include rare categories, model bias toward the training set, selecting operating thresholds, and making outputs understandable to users. Addressing such issues is often essential for practical success.
7.1 Class imbalance
Class imbalance occurs when some categories are much more common than others. In such cases, a model may learn to favor the majority class and ignore rare but important cases. This is common in fraud detection, medical screening, and anomaly-related tasks.
Possible remedies include resampling, class weighting, threshold adjustment, and specialized evaluation metrics. The best solution depends on the domain and the consequences of different mistakes.
7.2 Overfitting and underfitting
Overfitting happens when a model learns noise or overly specific patterns from the training data and performs poorly on new data. Underfitting occurs when the model is too simple to capture the underlying structure. Both problems limit generalization, though in different ways.
Good classification practice seeks a balance between flexibility and restraint. Validation methods, regularization, and careful model choice help manage this tradeoff.
7.3 Threshold selection
Many classifiers produce scores or probabilities that must be converted into class labels using a threshold. The default threshold is not always optimal. Changing it can increase recall at the expense of precision, or vice versa.
Threshold selection should reflect the practical costs of different errors. In some settings, the best threshold is chosen to maximize a metric; in others, it is determined by operational needs.
7.4 Calibration of predicted probabilities
Calibration refers to how closely predicted probabilities match actual frequencies. If a model assigns a probability of 0.8 to many cases, about 80 percent of those cases should truly belong to the class. Poor calibration can make probabilistic outputs misleading.
Calibration methods adjust probability estimates without necessarily changing the predicted labels. This is important when probabilities are used for decision-making, ranking, or risk assessment.
7.5 Interpretability
Interpretability is the extent to which humans can understand why a classifier made a prediction. Some models, such as small decision trees or logistic regression, are relatively transparent. Others, including large neural networks, are harder to explain.
Interpretability matters in settings where trust, auditing, or explanation are important. Even when a highly complex model performs best, simpler approximations or explanation tools may still be needed.
8 Applications
Classification is used in many areas because many real-world problems involve choosing among discrete categories. The input data and labels vary widely, but the underlying task remains the same: infer the most appropriate class from observed features. This versatility makes classification a core technique in applied machine learning.
8.1 Text classification
Text classification assigns categories to documents, messages, or sentences. Examples include topic labeling, sentiment analysis, and language identification. Text is often represented using word frequencies, embeddings, or other numerical encodings.
Because text data are high-dimensional and sparse, methods such as Naive Bayes, logistic regression, and neural networks are frequently used. Performance depends heavily on preprocessing and representation.
8.2 Image classification
Image classification identifies the subject or content of an image. Tasks may involve recognizing handwritten digits, object categories, medical images, or scene types. Feature extraction can be performed automatically by deep neural networks, especially convolutional architectures.
This field has become one of the most visible successes of modern machine learning. Large labeled datasets and powerful hardware have made high-performing image classifiers widely available.
8.3 Medical diagnosis
In medical settings, classification can support diagnostic screening, risk prediction, and triage. Models may estimate whether a patient is likely to have a condition based on test results, history, or imaging data. Because mistakes can have serious consequences, evaluation is often stricter than in many other domains.
Such systems are typically intended to assist rather than replace professional judgment. Probability estimates, calibration, and interpretability are especially important here.
8.4 Spam detection
Spam detection classifies messages as unwanted or legitimate. It is one of the classic applications of machine learning and has been used in email, messaging platforms, and content moderation systems. The task often involves text features, sender information, and behavioral signals.
Spam filters must adapt to changing patterns because malicious actors continually modify their tactics. This makes robust retraining and ongoing monitoring important.
8.5 Fraud detection
Fraud detection identifies transactions or activities that appear suspicious or inconsistent with normal behavior. Examples include unusual payment patterns, account abuse, and identity-related misuse. These problems are often characterized by rare positive cases and evolving tactics.
Because false positives can inconvenience users and false negatives can be costly, fraud systems often use probabilistic scoring, threshold tuning, and multiple layers of review. Classification is frequently combined with rules and anomaly methods.
9 Related concepts
Classification is closely connected to several other machine learning and information-processing tasks. Some are variations on prediction, while others focus on structure discovery or ordering rather than direct labeling. Understanding these relationships helps clarify where classification fits within the broader field.
9.1 Regression versus classification
Regression predicts continuous quantities, while classification predicts discrete categories. The two tasks often use similar tools, but the output type and evaluation criteria differ. A problem should be framed as one or the other depending on the nature of the target variable.
In some settings, the boundary between them is blurred, such as when a continuous score is later converted into categories. Even then, the final objective determines whether the problem is treated as regression or classification.
9.2 Clustering
Clustering is an unsupervised learning task that groups similar instances without using labeled targets. Unlike classification, it does not begin with predefined classes. The goal is to discover structure in unlabeled data.
Clustering can sometimes help prepare for classification by revealing natural groupings or suggesting features. However, the two tasks serve different purposes and require different forms of validation.
9.3 Ranking
Ranking orders items by relevance, preference, or predicted importance. Rather than assigning a discrete label, a ranking model produces an ordered list or score. This is useful in search, recommendation, and prioritization systems.
Classification and ranking can overlap when class probabilities are used to sort items. Even so, ranking emphasizes relative order, whereas classification emphasizes category assignment.
9.4 Anomaly detection
Anomaly detection seeks unusual instances that deviate from expected patterns. It may be framed as a classification problem when anomalies have labels, but it is often used when such labels are scarce or unavailable. The objective is to identify rare or irregular cases.
This concept is closely related to fraud detection and fault monitoring. In many applications, anomaly detection complements classification by flagging examples that do not fit known categories.