<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://www.baodoan.net/feed.xml" rel="self" type="application/atom+xml"/><link href="https://www.baodoan.net/" rel="alternate" type="text/html" hreflang="en"/><updated>2026-08-16T11:14:40+00:00</updated><id>https://www.baodoan.net/feed.xml</id><title type="html">Dr. Bao Gia Doan</title><subtitle>Academic website of Dr. Bao Gia Doan, a machine learning researcher at UNSW Sydney working on trustworthy AI, adversarial machine learning, privacy-preserving learning, and reliable retrieval-augmented generation systems. </subtitle><entry><title type="html">Train, Validation, and Test Sets: Measuring Generalization Correctly</title><link href="https://www.baodoan.net/blog/2026/train-validation-and-test-sets/" rel="alternate" type="text/html" title="Train, Validation, and Test Sets: Measuring Generalization Correctly"/><published>2026-08-15T23:00:00+00:00</published><updated>2026-08-15T23:00:00+00:00</updated><id>https://www.baodoan.net/blog/2026/train-validation-and-test-sets</id><content type="html" xml:base="https://www.baodoan.net/blog/2026/train-validation-and-test-sets/"><![CDATA[<p><em>This is the second post in the <a href="/blog/2026/ml-basics-and-concepts-series/">ML Basics and Concepts series</a>. It builds on <a href="/blog/2026/bias-and-variance/">Bias and Variance</a>.</em></p> <p>A model can achieve excellent performance on examples it has already seen and still fail on new ones. The central purpose of dataset splitting is to separate <strong>learning</strong> from <strong>evaluation</strong> so that we can answer the question that actually matters:</p> <blockquote> <p>How well will this model perform on future data drawn from the target population?</p> </blockquote> <p>The familiar train, validation, and test split is not merely an organizational convention. Each subset has a different statistical role. When those roles are mixed, information leaks into the learning process and the reported result becomes optimistic.</p> <h2 id="the-three-roles">The three roles</h2> <p>Suppose we begin with a dataset $D$ sampled from some population. We partition it into three disjoint subsets:</p> \[D = D_{\text{train}} \cup D_{\text{val}} \cup D_{\text{test}}.\] <table> <thead> <tr> <th>Subset</th> <th>Primary role</th> <th>What may depend on it?</th> </tr> </thead> <tbody> <tr> <td><strong>Training set</strong></td> <td>Fit model parameters</td> <td>Weights, coefficients, learned representations, and fitted preprocessing</td> </tr> <tr> <td><strong>Validation set</strong></td> <td>Make development decisions</td> <td>Architecture, hyperparameters, thresholds, feature choices, and stopping time</td> </tr> <tr> <td><strong>Test set</strong></td> <td>Estimate final generalization</td> <td>Ideally nothing; it is used only after the model and evaluation procedure are fixed</td> </tr> </tbody> </table> <p>The key distinction is between <strong>model parameters</strong> and <strong>development choices</strong>. Gradient descent may fit millions of weights using the training set, while the validation set determines choices such as depth, learning rate, regularization strength, data augmentation, or the epoch at which training stops. Both are forms of learning from data.</p> <p>The test set is different. It simulates data that remained unavailable throughout development.</p> <h2 id="why-training-performance-is-not-enough">Why training performance is not enough</h2> <p>A sufficiently flexible model can memorize its training examples. Its empirical training error,</p> \[\widehat R_{\text{train}}(h) = \frac{1}{|D_{\text{train}}|} \sum_{(x_i,y_i)\in D_{\text{train}}} \ell\!\left(h(x_i),y_i\right),\] <p>measures fit to the sample used for learning. It does not provide an independent estimate of the population risk</p> \[R(h)=\mathbb{E}_{(X,Y)\sim P}\left[\ell(h(X),Y)\right].\] <p>The gap between these quantities is the generalization gap. A validation or test set approximates population risk only when it has not already influenced the predictor in the way it is being evaluated.</p> <h2 id="the-validation-set-is-part-of-training">The validation set is part of training</h2> <p>Although no gradient may be computed directly from the validation set, repeated validation feedback guides development. Consider a workflow that tries 100 model configurations and keeps the one with the highest validation accuracy. The selected model benefits from information in that validation set: configurations that happened to match its noise were more likely to win.</p> <p>This is <strong>overfitting to the validation set</strong>. It becomes more severe when:</p> <ul> <li>many configurations are compared;</li> <li>the validation set is small or noisy;</li> <li>decisions are repeatedly made after inspecting individual errors;</li> <li>researchers manually adapt features or rules to validation examples;</li> <li>only the best result across many random seeds is reported.</li> </ul> <p>Validation data are therefore development data. They should not be treated as an untouched estimate of final performance.</p> <h2 id="why-the-test-set-should-be-used-once">Why the test set should be used once</h2> <p>The test set is intended to answer one final question after the model, preprocessing, decision threshold, and metric have been fixed. If its results influence another round of development, it has begun to act as a validation set.</p> <p>This does not mean a test set can literally be evaluated only once. The principle is that it should not provide an adaptive feedback loop. If we inspect the test result, change the system, and inspect it again many times, the final system can overfit the test set even without directly training on its examples.</p> <p>The same problem occurs at the community level. A public benchmark can become a shared validation set after years of model selection, paper writing, and leaderboard tuning. Honest progress then requires fresh test data or a hidden evaluation server.</p> <h2 id="choosing-the-split-proportions">Choosing the split proportions</h2> <p>Rules such as 70/15/15 or 80/10/10 are starting points, not laws. The right split is determined by the number of examples required for two competing goals:</p> <ol> <li>enough training data to learn a useful model;</li> <li>enough validation and test data to compare and estimate performance precisely.</li> </ol> <p>With millions of independent examples, even 1% may produce a large evaluation set. With a small dataset, fixed holdout sets may be too noisy, making cross-validation more useful.</p> <p>For a fixed classifier evaluated with <strong>0–1 loss</strong>, the empirical test error $\hat p$ is the proportion of misclassified examples:</p> \[\hat p = \frac{1}{N}\sum_{i=1}^{N} \mathbf{1}\!\left[h(x_i)\neq y_i\right].\] <p>Each test outcome is therefore treated as a Bernoulli variable: 1 when the prediction is wrong and 0 when it is correct. On $N$ approximately independent test examples, the estimated standard error of this proportion is</p> \[\operatorname{SE}(\hat p) \approx \sqrt{\frac{\hat p(1-\hat p)}{N}}.\] <p>This standard error measures <strong>finite-test-set sampling uncertainty</strong>. It describes how much the measured error would typically vary if we evaluated the same fixed classifier on another independent test set of size $N$ from the same distribution. A rough 95% confidence interval is $\hat p\pm1.96\operatorname{SE}(\hat p)$.</p> <p>It does not measure variation caused by retraining on different training sets, uncertainty in an individual prediction, or distribution shift. When examples are grouped or correlated, the effective sample size can be far smaller than $N$, so a group-aware confidence interval or bootstrap procedure is more appropriate.</p> <h2 id="choose-the-split-unit-before-the-split-method">Choose the split unit before the split method</h2> <p>The most important decision is often not the percentage but the <strong>unit that must be independent</strong>. Splitting individual rows is wrong when several rows come from the same underlying entity.</p> <p>Examples include:</p> <ul> <li>multiple images of the same patient;</li> <li>several frames from the same video;</li> <li>repeated transactions from one customer;</li> <li>patches cropped from the same source image;</li> <li>augmented versions of one original example;</li> <li>messages from the same conversation;</li> <li>measurements from the same machine or location.</li> </ul> <p>If related examples appear in both training and test sets, the model can exploit entity-specific information. The measured performance may then describe recognition of known entities rather than generalization to new ones.</p> <p>The safe rule is: <strong>split groups first, then construct examples or augmentations within each split</strong>.</p> <h2 id="common-splitting-strategies">Common splitting strategies</h2> <h3 id="random-split">Random split</h3> <p>A random split is appropriate when examples are approximately independent and identically distributed, and future data will come from the same stable population. It is simple and often effective, but it does not protect against hidden groups, duplicates, or temporal dependence.</p> <h3 id="stratified-split">Stratified split</h3> <p>A stratified split approximately preserves selected proportions—most commonly class frequencies—across subsets. It is useful when a random split might place too few minority-class examples in validation or test data.</p> <p>Stratification should not be confused with balancing. Preserving a naturally rare class keeps the evaluation representative; oversampling that class changes the evaluation distribution unless metrics are reweighted appropriately.</p> <h3 id="grouped-split">Grouped split</h3> <p>A grouped split keeps all examples from an entity in one subset. For medical imaging, the split is usually by patient rather than image. For document chunks, it may be by source document. For federated learning, it may be by client.</p> <p>This strategy evaluates the harder and often more relevant question: can the model generalize to unseen groups?</p> <h3 id="time-based-split">Time-based split</h3> <p>When a model predicts the future from the past, the split should respect time:</p> \[t_{\text{train}} &lt; t_{\text{val}} &lt; t_{\text{test}}.\] <p>Randomly moving future observations into the training set leaks information that would not have existed at deployment time. Time-based evaluation also exposes temporal drift in user behavior, prevalence, policy, sensors, or market conditions.</p> <h3 id="spatial-or-domain-based-split">Spatial or domain-based split</h3> <p>If deployment involves new hospitals, countries, cameras, environments, or data providers, holding out entire domains can be more informative than randomly holding out examples within every domain. The correct split should resemble the intended generalization boundary.</p> <h2 id="data-leakage">Data leakage</h2> <p><strong>Data leakage</strong> occurs when information unavailable at prediction time influences training or model selection. Leakage can make a weak model appear remarkably strong.</p> <h3 id="target-leakage">Target leakage</h3> <p>A feature directly or indirectly contains information about the target that would not be available when the prediction is made. For example, using a treatment prescribed after diagnosis to predict that diagnosis leaks the outcome timeline.</p> <h3 id="preprocessing-leakage">Preprocessing leakage</h3> <p>Any preprocessing step that learns from data must be fitted using the training set only. This includes:</p> <ul> <li>normalization means and variances;</li> <li>missing-value imputation;</li> <li>vocabulary construction;</li> <li>feature selection;</li> <li>dimensionality reduction;</li> <li>learned tokenization or representations;</li> <li>class-balancing procedures such as synthetic oversampling.</li> </ul> <p>The correct order is:</p> <ol> <li>split the raw examples;</li> <li>fit preprocessing on the training split;</li> <li>apply the fitted transformation to validation and test splits.</li> </ol> <p>A pipeline abstraction is valuable because it binds preprocessing and model fitting into one procedure and reduces accidental leakage during cross-validation.</p> <h3 id="duplicate-and-augmentation-leakage">Duplicate and augmentation leakage</h3> <p>Exact duplicates, near-duplicates, or augmented versions of the same example must not cross split boundaries. Deduplication should consider semantics, not only identical file hashes: resized images, copied text with minor edits, and overlapping time windows can still reveal almost the same example.</p> <h3 id="selection-leakage">Selection leakage</h3> <p>Selecting features, thresholds, prompts, or checkpoints after observing test results leaks test information into the final system. Even an apparently harmless manual inspection can become selection leakage when it changes what is submitted or reported.</p> <h2 id="cross-validation">Cross-validation</h2> <p>When data are limited, one validation split may give an unstable comparison. In $K$-fold cross-validation, the development data are divided into $K$ folds. Each fold serves as validation data once while the remaining $K-1$ folds are used for training:</p> \[\widehat R_{\text{CV}} = \frac{1}{K}\sum_{k=1}^{K}\widehat R^{(k)}_{\text{val}}.\] <p>The average gives a more stable estimate for model selection, and variation across folds reveals sensitivity to the sampled data. The fold construction must still obey the correct unit: use stratified folds for class proportions, group folds for entities, and forward-chaining splits for time series.</p> <p>Cross-validation does not eliminate the need for an independent test set when a final unbiased estimate is required. The usual workflow is:</p> <ol> <li>reserve the test set;</li> <li>use cross-validation within the remaining development data;</li> <li>select the model and hyperparameters;</li> <li>optionally refit the fixed procedure on all development data;</li> <li>evaluate once on the reserved test set.</li> </ol> <p>When both model selection and performance estimation must use resampling, <strong>nested cross-validation</strong> places model selection in an inner loop and evaluation in an outer loop. It is more expensive but avoids evaluating a hyperparameter search on the same folds that selected it.</p> <h2 id="distribution-mismatch">Distribution mismatch</h2> <p>Independence is not enough. Validation and test data must also represent the distribution we care about.</p> <p>Suppose a model is trained on studio photographs but deployed on mobile-phone images. A random split of the studio dataset can produce an accurate estimate of performance on more studio photographs while saying little about deployment. The estimate is statistically valid for the wrong population.</p> <p>Useful questions include:</p> <ul> <li>Do class frequencies match deployment?</li> <li>Are devices, locations, demographics, and time periods represented?</li> <li>Does data collection reproduce the information available at prediction time?</li> <li>Are rare but important operating conditions present?</li> <li>Is the label definition consistent across splits and deployment?</li> </ul> <p>Sometimes training data are intentionally broader or rebalanced. That can be useful, but validation and test sets should still reflect the target population or be reweighted to a clearly defined target distribution.</p> <p>If multiple deployment domains matter, report results separately rather than hiding failures inside a single average.</p> <h2 id="connecting-splits-to-bias-and-variance">Connecting splits to bias and variance</h2> <p>The <a href="/blog/2026/bias-and-variance/">previous article</a> used training and validation errors as practical diagnostics. With a trustworthy split, their pattern provides an initial signal:</p> <table> <thead> <tr> <th>Training result</th> <th>Validation result</th> <th>Likely interpretation</th> </tr> </thead> <tbody> <tr> <td>Poor</td> <td>Poor and similar</td> <td>High bias, weak features, optimization failure, or noisy labels</td> </tr> <tr> <td>Strong</td> <td>Much poorer</td> <td>High variance, leakage in training evaluation, or distribution mismatch</td> </tr> <tr> <td>Strong</td> <td>Strong</td> <td>Good fit on the validation distribution; final test evaluation is still needed</td> </tr> <tr> <td>Poor</td> <td>Surprisingly strong</td> <td>Small-sample noise, inconsistent pipelines, or an implementation error</td> </tr> </tbody> </table> <p>Learning curves make the diagnosis more informative. Plot training and validation performance as the training-set size increases. A persistent high error in both curves suggests bias. A large gap that narrows with more data suggests variance.</p> <p>These patterns are clues rather than proofs. Before changing model capacity, verify the split, metric, labels, and preprocessing pipeline.</p> <h2 id="a-practical-workflow">A practical workflow</h2> <ol> <li><strong>Define deployment first.</strong> Specify the population, prediction time, available inputs, target, and metric.</li> <li><strong>Identify dependence.</strong> Decide whether the split unit is an example, person, document, device, location, or time period.</li> <li><strong>Reserve the test set.</strong> Keep it inaccessible during routine development.</li> <li><strong>Split before preprocessing or augmentation.</strong> Fit every learned transformation using training data only.</li> <li><strong>Develop with validation data.</strong> Use a holdout set or an appropriate form of cross-validation.</li> <li><strong>Track all adaptive decisions.</strong> Architecture searches, prompt changes, threshold selection, and manual error analysis all consume validation information.</li> <li><strong>Freeze the procedure.</strong> Fix preprocessing, hyperparameters, checkpoint selection, threshold, and metric.</li> <li><strong>Evaluate the test set once for the final claim.</strong> Report uncertainty and relevant subgroup or domain results.</li> <li><strong>Create fresh test data after further iteration.</strong> Once test feedback changes the system, that test set is no longer fully untouched.</li> </ol> <h2 id="takeaways">Takeaways</h2> <ul> <li>Training data fit parameters; validation data guide development; test data estimate final generalization.</li> <li>Repeatedly adapting to validation or test results causes evaluation overfitting.</li> <li>Split by the unit that must generalize: patient, document, device, location, or time, not automatically by row.</li> <li>Perform learned preprocessing and augmentation only after the split boundaries are established.</li> <li>Cross-validation reduces dependence on one validation split but does not excuse leakage or an inappropriate split strategy.</li> <li>An independent test set is useful only when it represents the deployment population.</li> <li>Report uncertainty: test performance is an estimate based on a finite sample, not a permanent property of the model.</li> </ul>]]></content><author><name></name></author><category term="ML Basics and Concepts"/><category term="machine-learning"/><category term="fundamentals"/><category term="generalization"/><category term="evaluation"/><category term="tutorial"/><summary type="html"><![CDATA[How to split data, prevent leakage, choose models, and obtain an honest estimate of performance on unseen examples.]]></summary></entry><entry><title type="html">Bias and Variance: Understanding Underfitting and Overfitting</title><link href="https://www.baodoan.net/blog/2026/bias-and-variance/" rel="alternate" type="text/html" title="Bias and Variance: Understanding Underfitting and Overfitting"/><published>2026-08-13T23:00:00+00:00</published><updated>2026-08-13T23:00:00+00:00</updated><id>https://www.baodoan.net/blog/2026/bias-and-variance</id><content type="html" xml:base="https://www.baodoan.net/blog/2026/bias-and-variance/"><![CDATA[<p><em>This is the first post in the <a href="/blog/2026/ml-basics-and-concepts-series/">ML Basics and Concepts series</a>.</em></p> <p>A machine learning model must do more than fit its training data. It must learn a pattern that continues to work on examples it has never seen. Bias and variance describe two different ways this can go wrong:</p> <ul> <li><strong>High bias</strong> means the model is too restricted to capture the relevant pattern. It <strong>underfits</strong>.</li> <li><strong>High variance</strong> means the model is too sensitive to the particular training sample. It <strong>overfits</strong>.</li> </ul> <p>The best model is not necessarily the most complex one or the one with the lowest training error. It is the model that generalizes best to the data we will encounter after training.</p> <blockquote> <p>Here, <strong>bias</strong> means statistical bias in a learning procedure. It is different from social or demographic bias in data and model predictions.</p> </blockquote> <h2 id="the-learning-setup">The learning setup</h2> <p>Suppose examples are drawn from an unknown distribution</p> \[(X,Y) \sim P(X,Y),\] <p>and a training set $D$ is sampled from this distribution. A learning algorithm uses $D$ to produce a predictor $\hat f_D$. If we drew a different training set, we would generally obtain a different predictor.</p> <p>This gives us two questions:</p> <ol> <li>On average, how far is the learned prediction from the true relationship?</li> <li>How much does the learned prediction change when the training sample changes?</li> </ol> <p>The first question is about <strong>bias</strong>. The second is about <strong>variance</strong>.</p> <h2 id="bias-error-from-restrictive-assumptions">Bias: error from restrictive assumptions</h2> <p>Bias measures the systematic error introduced by the assumptions of the model and learning algorithm. A high-bias model cannot represent the important structure in the data, even when it is trained correctly.</p> <p>Imagine fitting a straight line to a relationship that is strongly curved. More data will locate the best straight line more precisely, but it will not make that line curved. The model class itself is too restrictive.</p> <p>Typical signs of high bias are:</p> <ul> <li>training error is high;</li> <li>validation error is also high;</li> <li>the gap between training and validation error is relatively small;</li> <li>increasing the amount of training data produces little improvement.</li> </ul> <p>High bias is therefore associated with <strong>underfitting</strong>.</p> <p>Possible responses include using a richer model, constructing more informative features, reducing excessive regularization, or fixing an optimization problem that prevents the model from fitting even the training data.</p> <h2 id="variance-error-from-sensitivity-to-the-sample">Variance: error from sensitivity to the sample</h2> <p>Variance measures how much the learned predictor would change if it were trained on a different dataset sampled from the same population. A high-variance model learns not only the underlying pattern but also accidental details and noise in its training sample.</p> <p>A very flexible curve may pass through every training point while behaving unpredictably between those points. Its training error can be extremely low, yet its error on new data can be much higher.</p> <p>Typical signs of high variance are:</p> <ul> <li>training error is low;</li> <li>validation error is substantially higher;</li> <li>performance changes noticeably across folds, random seeds, or resampled datasets;</li> <li>adding representative training data improves validation performance.</li> </ul> <p>High variance is therefore associated with <strong>overfitting</strong>.</p> <p>Possible responses include collecting more representative data, strengthening regularization, simplifying the model, using data augmentation, stopping training earlier, or averaging several models through an ensemble.</p> <h2 id="the-biasvariance-trade-off">The bias–variance trade-off</h2> <p>For squared-error regression, the expected prediction error at an input $x$ has the familiar decomposition</p> \[\mathbb{E}_D\!\left[(Y-\hat f_D(x))^2\mid X=x\right] = \operatorname{Bias}(x)^2 + \operatorname{Variance}(x) + \sigma^2(x),\] <p>where</p> \[\operatorname{Bias}(x) = \mathbb{E}_D[\hat f_D(x)]-f(x),\] <p>and</p> \[\operatorname{Variance}(x) = \mathbb{E}_D\!\left[ \left(\hat f_D(x)-\mathbb{E}_D[\hat f_D(x)]\right)^2 \right].\] <p>and $\sigma^2(x)$ is irreducible noise in $Y$ given $X=x$.</p> <p>Increasing model flexibility often reduces bias because the model can represent more complex patterns. The same flexibility can increase variance because the fitted model has more ways to respond to fluctuations in a finite training set. Regularization moves in the opposite direction: it usually increases bias while reducing variance.</p> <p>The trade-off is not a law that one side must always worsen when the other improves. Better features, a more appropriate inductive bias, or more representative data can improve both. It is nevertheless a useful way to diagnose errors.</p> <p>For classification and other losses, the clean squared-error equation does not carry over unchanged. Bias and variance remain useful concepts, but their exact decomposition depends on the loss and the definition being used.</p> <h2 id="a-practical-diagnosis">A practical diagnosis</h2> <p>Training and validation errors provide a useful first check:</p> <table> <thead> <tr> <th>Observation</th> <th>Likely problem</th> <th>Useful next step</th> </tr> </thead> <tbody> <tr> <td>High training error and high validation error</td> <td>High bias / underfitting</td> <td>Increase suitable capacity, improve features, or reduce excessive regularization</td> </tr> <tr> <td>Low training error and much higher validation error</td> <td>High variance / overfitting</td> <td>Add data or augmentation, regularize, simplify, or ensemble</td> </tr> <tr> <td>Low training and validation error</td> <td>Good fit on the current distribution</td> <td>Test robustness, calibration, and distribution shift</td> </tr> <tr> <td>High training error despite a powerful model</td> <td>Optimization or data problem may dominate</td> <td>Check labels, preprocessing, loss, learning rate, and convergence</td> </tr> </tbody> </table> <p>These are diagnostics, not proofs. A validation set drawn from the wrong distribution can hide both underfitting and overfitting. Label leakage can make validation error look excellent while real deployment performance is poor.</p> <h2 id="bayes-error-the-ideal-classifiers-limit">Bayes error: the ideal classifier’s limit</h2> <p>Even with unlimited data and a sufficiently capable model, classification error may not be zero. The input can be ambiguous, relevant information can be missing, labels can be noisy, or the outcome itself can be stochastic.</p> <p>Assume we know the true conditional distribution $P(Y\mid X)$. Under 0–1 loss, the <strong>Bayes classifier</strong> predicts the most probable class:</p> \[f^*(x)=\arg\max_y P(Y=y\mid X=x).\] <p>Its expected error is the <strong>Bayes error</strong> or <strong>Bayes risk</strong>:</p> \[R^* = \mathbb{E}_X\left[1-\max_y P(Y=y\mid X)\right].\] <p>No classifier using the same input $X$, evaluated on the same distribution with the same 0–1 loss, can achieve a lower expected error. Bayes error is therefore the theoretical <strong>lower bound</strong> for that learning problem.</p> <p>The qualification “using the same input” matters. Suppose two classes look identical in an image but can be distinguished with an additional sensor. The image-only task can have positive Bayes error even though the richer task does not. What appears to be irreducible error may be uncertainty created by an incomplete representation of the world.</p> <h2 id="why-bayes-error-can-only-be-estimated">Why Bayes error can only be estimated</h2> <p>In real problems, we do not know the true $P(Y\mid X)$. We only observe a finite sample from the world, so we generally cannot compute $R^*$ exactly. We can only construct proxies.</p> <h3 id="fit-a-calibrated-probabilistic-model">Fit a calibrated probabilistic model</h3> <p>A direct approach is to train a probabilistic classifier—such as logistic regression or a neural network with a softmax output—to estimate</p> \[\widehat P(Y\mid X)=P(Y\mid X,\theta),\] <p>where $\theta$ is learned from data. Given a large independent test set ${x_i}_{i=1}^N$, we can form the plug-in estimate</p> \[\widehat R_{\text{plugin}} = \frac{1}{N}\sum_{i=1}^N \left(1-\max_y \widehat P(Y=y\mid x_i)\right).\] <p>This is intuitive for deep learning because the model already outputs an estimated class distribution. It is reliable only when those probabilities are close to the true conditional probabilities. Good calibration is important: a model that reports 90% confidence should be correct roughly 90% of the time on comparable examples. Calibration alone is not sufficient, however, because aggregate calibration can hide large local errors in $\widehat P(Y\mid X=x)$.</p> <p>The test set must also be independent and representative of the deployment distribution. Otherwise, the estimate describes the wrong prediction problem.</p> <h3 id="estimate-class-conditional-densities">Estimate class-conditional densities</h3> <p>For a simpler low-dimensional problem, we can estimate each class-conditional density $p(x\mid Y=k)$ and the class prior $P(Y=k)$. Bayes’ rule then gives</p> \[P(Y=k\mid x) = \frac{p(x\mid Y=k)P(Y=k)} {\sum_j p(x\mid Y=j)P(Y=j)}.\] <p>Once this posterior has been estimated, it can be inserted into the Bayes-risk formula. Gaussian density models, kernel density estimation, and nearest-neighbor probability estimates are possible choices.</p> <p>This approach becomes difficult in high-dimensional spaces. Density estimation in image or language input spaces usually requires an enormous amount of data and strong modeling assumptions, so the resulting Bayes-error estimate can be dominated by density-estimation error.</p> <h3 id="repeated-labels-and-human-level-performance">Repeated labels and human-level performance</h3> <p>Collecting several independent labels for the same input gives more information than forcing a single “ground-truth” label. If 90 out of 100 reliable annotators label an example as class A and 10 label it as class B, we might estimate</p> \[P(A\mid x)\approx 0.9, \qquad P(B\mid x)\approx 0.1.\] <p>The estimated local Bayes error for that example is then</p> \[1-\max\{0.9,0.1\}=0.1.\] <p>This interpretation assumes that the variation in labels reflects genuine conditional uncertainty. Annotators can instead share systematic mistakes, use different labeling rules, or lack relevant context. Clear instructions, reliable annotators, independent judgments, and adjudication are therefore important.</p> <p>Human error is not the formal Bayes lower bound: people can make systematic mistakes, and a classifier may outperform them. It is better understood as a practical measure of task difficulty. Repeated disagreement can reveal ambiguity, missing information, or label noise, while expert consensus can expose errors in the dataset labels.</p> <h3 id="use-strong-models-as-a-practical-proxy">Use strong models as a practical proxy</h3> <p>In modern high-dimensional problems, exact estimation is usually impossible. If several powerful model families trained on large datasets converge to roughly the same test error, their performance provides a useful practical reference. For any particular classifier $h$,</p> \[R^*\leq R(h).\] <p>The same applies to the strongest model we have trained:</p> \[R^*\leq R(h_{\text{best}}).\] <p>If the best network obtains 3% test error, then—after accounting for finite-test-set uncertainty—we have evidence that $R^*$ is no greater than approximately 3%. We cannot conclude that the Bayes error is exactly 3%.</p> <p>However, this achieved error is normally an <strong>upper bound</strong> on Bayes error, not proof of the lower bound: the model can still have approximation error, estimation error, optimization error, or distribution mismatch. A larger model is a better proxy only when its predictions are supported by sufficient data and evaluated properly.</p> <p>None of these approaches recovers the true world model from limited data. They give increasingly useful approximations to the best achievable performance under a clearly defined input, target, distribution, and loss.</p> <h2 id="reducible-and-irreducible-error">Reducible and irreducible error</h2> <p>A helpful conceptual summary is</p> \[\text{generalization error} \approx \text{Bayes error} + \text{approximation error} + \text{estimation error} + \text{optimization error}.\] <p>This is a conceptual accounting for classification, not a universal exact additive identity.</p> <ul> <li><strong>Bayes error</strong> is irreducible without changing the information, target, loss, or data-generating process.</li> <li><strong>Approximation error</strong> arises when the model family cannot represent a sufficiently good decision rule; it is closely related to high bias.</li> <li><strong>Estimation error</strong> arises because the learner sees only finite data; it is closely related to high variance.</li> <li><strong>Optimization error</strong> arises when training fails to find the best available model in the chosen family.</li> </ul> <p>This distinction prevents a common mistake: blaming every stubborn error on model capacity. Sometimes a model underfits. Sometimes it overfits. Sometimes training is poor. And sometimes the input simply does not contain enough information to determine the label reliably.</p> <h2 id="takeaways">Takeaways</h2> <ul> <li>High bias usually appears as underfitting: both training and validation errors stay high.</li> <li>High variance usually appears as overfitting: training error is low but validation error is much higher.</li> <li>Model capacity, regularization, data quantity, and inductive bias determine where a learner sits between these two failure modes.</li> <li>Bayes error is the theoretical lower bound for a fixed prediction problem, but the true $P(Y\mid X)$ is unknown in practice.</li> <li>Strong models, reliable human annotators, and repeated labels can provide useful proxies for task difficulty, but their observed errors are not themselves proofs of the Bayes lower bound.</li> </ul>]]></content><author><name></name></author><category term="ML Basics and Concepts"/><category term="machine-learning"/><category term="fundamentals"/><category term="bias-variance"/><category term="tutorial"/><summary type="html"><![CDATA[How bias, variance, and Bayes error explain a model's generalization error—and what training and validation results can tell us.]]></summary></entry><entry><title type="html">The ML Basics and Concepts Series</title><link href="https://www.baodoan.net/blog/2026/ml-basics-and-concepts-series/" rel="alternate" type="text/html" title="The ML Basics and Concepts Series"/><published>2026-08-13T22:00:00+00:00</published><updated>2026-08-13T22:00:00+00:00</updated><id>https://www.baodoan.net/blog/2026/ml-basics-and-concepts-series</id><content type="html" xml:base="https://www.baodoan.net/blog/2026/ml-basics-and-concepts-series/"><![CDATA[<p>This series collects my notes on the foundations of machine learning. The goal is to connect familiar terms to the reasoning behind them: what each concept means, how it appears in experiments, and what we can do about it in practice.</p> <p>The guiding question is:</p> <blockquote> <p>What does a model’s error tell us about the data, the learning algorithm, and the task itself?</p> </blockquote> <h2 id="reading-order">Reading order</h2> <ol> <li> <p><a href="/blog/2026/bias-and-variance/">Bias and Variance</a></p> <p>Why high bias leads to underfitting, why high variance leads to overfitting, and where Bayes error sets the irreducible limit.</p> </li> <li> <p><a href="/blog/2026/train-validation-and-test-sets/">Train, Validation, and Test Sets</a></p> <p>How to measure generalization without leaking information, overfitting the evaluation, or testing on data that does not represent deployment.</p> </li> </ol> <h2 id="topics-to-expand-later">Topics to expand later</h2> <p>Future notes will build on this foundation with topics such as:</p> <ul> <li>regularization and model capacity;</li> <li>loss functions and evaluation metrics;</li> <li>maximum likelihood and maximum a posteriori estimation;</li> <li>calibration, uncertainty, and distribution shift.</li> </ul> <p>The series will grow as I add concise explanations, mathematical intuition, and practical diagnostics for each concept.</p>]]></content><author><name></name></author><category term="ML Basics and Concepts"/><category term="machine-learning"/><category term="fundamentals"/><category term="tutorial"/><summary type="html"><![CDATA[A guided series on the core ideas that shape how machine learning models learn, generalize, and fail.]]></summary></entry></feed>