"Give me thirty labeled examples and a physicist, and I will beat your transformer before it finishes its first epoch."
A Frugal AI Agent
The Big Picture
Everything so far in this chapter built a table: rows are windows, columns are the time-domain, spectral, statistical, and library-generated features of Sections 8.1 through 8.4, trimmed by the selection of Section 8.5 and compressed by the projections of Section 8.6. It is tempting to treat that whole enterprise as a quaint prelude to Chapter 13, where a network learns its own features end to end. That framing is wrong often enough to be dangerous. On a large fraction of real sensor problems (the ones with a few hundred labeled windows, a microcontroller for a compute budget, an auditor who wants to know why the alarm fired, or a deployment that will see conditions the training set never did) a handful of handcrafted features fed to gradient-boosted trees still wins on accuracy, latency, cost, and trust simultaneously. This section is a decision procedure: it names the four regimes where features beat deep learning, explains the mechanism behind each, and tells you the honest signals that mean it is time to switch.
This section assumes the bias-variance intuition from Chapter 4 and the leakage-safe evaluation discipline of Chapter 5, because every claim below is a claim about generalization, and generalization claims are only as trustworthy as the split that produced them. It is deliberately not a rejection of deep learning; it is the boundary condition that tells you when the rest of Part IV pays for itself.
Four regimes where features win
The advantage of handcrafted features is not nostalgia, it is a set of concrete resource and structure conditions. Four recur across sensing.
Data scarcity. A feature is a hand-injected prior: the crest factor "knows" that impulsiveness matters, so the model does not have to discover that from data. A deep network must learn both the feature and the decision boundary from the same limited labels, spending its sample budget twice. When you have hundreds to low-thousands of labeled windows (the norm in clinical studies, industrial fault datasets, and any setting where a human had to annotate) the network's flexibility becomes variance, not skill. This is why gradient-boosted trees on tabular features remain the strongest baseline on most small and medium time-series classification tasks, a result that keeps re-appearing across the UCR/UEA archives and tabular benchmarks.
Edge and cost constraints. Twenty features and a depth-6 tree ensemble run in microseconds on a Cortex-M4, need no accelerator, and quantize losslessly. A learned representation of comparable accuracy may need orders of magnitude more multiply-accumulates and megabytes of weights. When the target is a coin-cell wearable or a batteryless tag, the feature pipeline is often the only thing that fits, a tradeoff Chapter 59 quantifies in detail.
Interpretability and regulation. "The alarm fired because kurtosis exceeded 6 and band-power in 2 to 4 kHz doubled" is a sentence an auditor, a clinician, or a safety case can act on. A saliency map over a raw waveform is not. In regulated domains (medical devices under the validation regime of Chapter 34, functional safety in vehicles) the burden of explanation frequently decides the architecture before accuracy does.
Distribution shift. Physically grounded, dimensionless features often transfer across operating conditions that break a network. A crest factor is invariant to sensor gain; a spectral ratio is invariant to load; these invariances were designed in, not hoped for. A network trained end to end can latch onto a spurious cue (a specific noise floor, a device serial signature) that vanishes at deployment, the failure mode studied in Chapter 66.
Key Insight: A Feature Is Borrowed Sample Efficiency
Deep learning's win is asymptotic: as labels \(n\to\infty\), a model that learns its own features can represent functions no fixed feature set can, so its error floor is lower. Handcrafted features win in the pre-asymptotic regime because each feature is a decade of domain knowledge substituting for thousands of labels you do not have. Formally, features lower the hypothesis-space complexity and thus the variance term, at the cost of a bias term you accept because the prior is good. The practical corollary: the crossover point where deep learning overtakes features is not fixed, it moves left as your labeled dataset grows and right as your prior gets better. Estimate where you sit on that curve before choosing an architecture, not after.
The showdown, measured fairly
The only credible way to know which side of the crossover you are on is to run both under one leakage-safe protocol. The code below builds a small human-activity-recognition problem (the domain of Chapter 26), extracts a dozen classical features per window, and pits gradient-boosted trees against a compact 1-D convolutional network under a subject-wise split so that no subject appears in both train and test.
import numpy as np
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.metrics import f1_score
from scipy.stats import kurtosis
rng = np.random.default_rng(0)
fs, W = 50, 128 # 50 Hz, ~2.5 s windows
def make_subject(label_shift): # each "subject" has its own bias
n = 60
X = rng.normal(label_shift, 1.0, (n, W))
y = (rng.random(n) < 0.5).astype(int)
X[y == 1] += 0.8 * np.sin(2*np.pi*3*np.arange(W)/fs) # class-1 tremor
return X + rng.normal(0, 0.3, (n, W)), y
def features(X): # 6 cheap, physically meaningful columns
return np.column_stack([
X.mean(1), X.std(1), kurtosis(X, axis=1),
np.abs(np.fft.rfft(X, axis=1))[:, 2:6].sum(1), # 2-6 bin band power
np.sqrt((X**2).mean(1)), np.diff(X, axis=1).std(1)])
train = [make_subject(s) for s in (-0.5, 0.0, 0.5, 1.0)] # 4 train subjects
Xtr = np.vstack([x for x, _ in train]); ytr = np.concatenate([y for _, y in train])
Xte, yte = make_subject(2.0) # unseen subject bias
gbt = HistGradientBoostingClassifier(max_depth=4).fit(features(Xtr), ytr)
print("features+GBT macro-F1:", round(f1_score(yte, gbt.predict(features(Xte)), average="macro"), 3))
X to see the crossover move as you add subjects.The lesson of the block is not that trees always win. It is that the fair comparison is subject-wise and construct-matched, and that with four subjects and 240 windows the feature model transfers to the fifth subject's baseline shift because that invariance was engineered in. Add twenty subjects and thousands of windows, and the CNN's learned features start to close and then overtake the gap. The experiment tells you where you are, which is the only thing worth knowing.
Practical Example: A Bearing Fault Classifier That Shipped on Trees
An industrial drives team needed to classify four bearing fault states from a single accelerometer across a family of motors running at loads the lab never fully replicated. They had roughly 900 labeled runs. A deep 1-D residual network reached 96 percent on a random split and collapsed to 71 percent on a machine-wise split, having memorized per-machine noise signatures. A pipeline of eleven features (envelope-spectrum band powers around the bearing characteristic frequencies, crest factor, and kurtosis) into gradient-boosted trees held 92 percent machine-wise, ran in 40 microseconds on the existing drive controller, and produced a per-fault feature-importance report the reliability engineers could sign off on. The features encoded the bearing physics of Chapter 36 directly, so the model never had a chance to learn the machine-identity shortcut. The trees shipped; the network became the roadmap for when the fleet grows past ten thousand labeled runs.
When to switch: the honest signals
Features stop being the right tool when the pre-asymptotic advantages erode. Reach for the learned representations of Part IV when several of these hold: labeled data is abundant (tens of thousands of windows and climbing); the discriminative structure is a subtle morphology or long-range temporal pattern that resists compact description (raw waveform shape in Chapter 29, multi-scale context a transformer captures); the input is high-dimensional and spatial (lidar, depth, imaging), where hand-features are hopeless; or you can amortize labels through the self-supervised pretraining of Chapter 17 and the foundation models of Chapter 20. A powerful hybrid, and often the actual production answer, is to feed engineered features and a learned embedding to the same classifier, or to use features as a cheap always-on gate that wakes a heavier model only on interesting windows.
Right Tool: The Whole Showdown in a Dozen Lines
Running the honest comparison by hand (grouped splitting, a construct-matched metric computed in one pass, cross-validated) is easy to get subtly wrong. scikit-learn's cross_validate with a GroupKFold collapses the correct subject-wise protocol into a few lines:
from sklearn.model_selection import cross_validate, GroupKFold
scores = cross_validate(gbt, features(Xtr), ytr, groups=subject_id,
cv=GroupKFold(4), scoring="f1_macro")
print(scores["test_score"].mean())
This replaces roughly 30 to 40 lines of manual fold construction, leak-checking, and metric aggregation, and it makes the grouping explicit so a reviewer can see that no subject straddles the split. The library owns the plumbing; you still own choosing groups correctly, which is the only decision that matters.
scikit-learn owning the split and metric aggregation.Exercise
Using the showdown skeleton: (1) add a small 1-D CNN trained on raw X and plot macro-F1 of both models as you grow the number of training subjects from 2 to 20; mark the crossover. (2) Replace the subject-wise test with a random split and show how it flatters the CNN, then explain which number you would put in a report. (3) Remove the band-power feature and observe which model degrades more, and argue what that says about where the tremor prior was living.
Self-Check
- In bias-variance terms, why does a handcrafted feature help most exactly when labels are scarce, and why does that advantage shrink as \(n\) grows?
- A network scores 96 percent on a random split and 71 percent machine-wise. What went wrong, and why might dimensionless features be more robust to it?
- Name two deployment conditions under which you would choose features even if a deep model were one point more accurate on a held-out set.
Lab 8
build a feature-based activity/condition classifier; compare against a small neural baseline and analyze where each wins.
Bibliography
Why trees still win on tabular and small time-series data
The canonical modern demonstration that gradient-boosted trees beat deep nets on most medium-sized tabular problems, with an analysis of why: rotation invariance, robustness to uninformative features, and smoothness assumptions. Directly explains the feature-table advantage of this section.
The benchmark suite on which classical feature and distance methods remain competitive with deep models across a large fraction of datasets, especially the small ones. The empirical backbone for the "features win pre-asymptotically" claim.
A rigorous survey pitting deep architectures against strong classical baselines on the UCR/UEA archives, quantifying exactly where and by how much deep learning does or does not help.
Feature libraries and fast classical baselines
The feature-factory approach that makes the handcrafted-feature route cheap enough to always try first, with built-in relevance filtering to control the resulting dimensionality.
Twenty-two features selected for accuracy and low redundancy across thousands of tasks, the minimal feature set that a deep model must beat to justify its cost.
A middle path: random (unlearned) convolutional features plus a linear classifier match or beat deep nets at a fraction of the training cost, blurring the feature-versus-deep boundary this section draws.
The learned-representation side of the crossover
Representative of the abundant-data, amortized-label regime where pretrained representations overtake handcrafted features, defining the right edge of the crossover curve.
An open time-series foundation model whose few-shot behavior is the natural comparison point when deciding whether to leave handcrafted features behind.
A large-label, subtle-morphology case where end-to-end deep learning clearly beats hand-features, illustrating the conditions that flip the decision toward Part IV.
What's Next
In Chapter 9, we leave feature tables and static classification behind and pick up the probabilistic backbone of sensing: the Kalman family, which fuses a motion model with noisy measurements to track a hidden state through time. Where this chapter asked "what does this window look like," the next asks "given everything I have seen, what is the system doing right now."