# Bayesian Classifiers

A Machine Learning concept (Learned models) in the LuxAlgo Library.

## What are Bayesian Classifiers?

A Bayesian classifier assigns a probability to each possible outcome class, such as price up versus price down over the next several bars, by applying Bayes' theorem: the posterior probability of a class is proportional to its prior probability multiplied by the likelihood of the observed features under that class. The most common variant in trading tools is naive Bayes, which assumes the features are conditionally independent given the class, so the joint likelihood factorizes into a product of simple per-feature terms that can be estimated from modest amounts of history.

That independence assumption is almost always false for market inputs, since momentum readings, volume measures, and structure flags move together, yet naive Bayes often still ranks outcomes usefully because the violation inflates confidence more than it scrambles ordering. The practical consequence is that posteriors from a naive model tend to be overconfident, pushed toward 0 or 1, so they are better treated as scores to rank and filter with than as literal odds, a concern shared with [logistic signal calibration](https://www.luxalgo.com/library/concept/logistic-signal-calibration/).

The machinery is refreshingly inspectable. Priors come from class frequencies in the training window, how often the market rose versus fell over the chosen horizon. Likelihoods come from counting: for a discretized feature such as an RSI zone or a delta sign, each bin's frequency under each class is a table entry, while Gaussian naive Bayes fits a mean and variance per feature per class for continuous inputs. Classification then just accumulates log-likelihood ratios feature by feature, which means every input's contribution to the verdict can be printed and audited, a transparency that black-box models never offer.

Practice adds three refinements. Counting tables update incrementally, so the model suits [online learning](https://www.luxalgo.com/library/concept/online-incremental-learning/), refreshing bar by bar without refitting; correlated inputs deserve pruning or decorrelation through [PCA](https://www.luxalgo.com/library/concept/pca/) before they double-count the same evidence; and the overconfident posteriors calibrate well through the standard mapping fixes. On-chart implementations exist precisely because the arithmetic is light, the Library's naive Bayes order-flow study being one example, with the counting tables living in arrays and the class verdict recomputed per bar.

## How to identify a Bayesian classifier's construction

Everything reduces to priors, likelihood tables, and a threshold; auditing one means walking those parts.

1. Pin down the label first: which classes the model separates and over what horizon, the [label definition](https://www.luxalgo.com/library/concept/label-definition-and-prediction-horizon/) that everything downstream answers to.
2. Check the priors: class frequencies from the training window, and whether they update as the window rolls.
3. Inspect the likelihoods: binned frequency tables per feature per class, or per-class Gaussians for continuous features, and how much history estimated them.
4. Follow the accumulation: per-feature log-likelihood ratios summing into a posterior, which makes each input's contribution explicit.
5. Test the output honestly: threshold the posterior, calibrate it if it will be read as a probability, and validate out of sample before trusting either.

## How traders use it

- As a directional scorer: several [engineered features](https://www.luxalgo.com/library/concept/feature-engineering/), such as oscillator zones or order-flow readings, are fused into one posterior probability of an up or down outcome, traded only above a threshold.
- As a filter on another system: an existing signal fires only when the classifier's posterior for the favorable class is high enough, suppressing entries the evidence does not support.
- As an evidence combiner: each feature multiplies the running odds by its historical likelihood ratio, keeping every input's contribution explicit and inspectable.
- In online form: the counting tables update with each new labeled bar, so the classifier tracks slowly drifting conditions without scheduled refits, at the cost of also absorbing whatever regime noise arrives.
- With input hygiene: pruning redundant features or decorrelating them first prevents the independence assumption from double-counting one signal heard through several instruments, which is the main source of the model's overconfidence.

## Bayesian classifiers vs other learned models

- **Logistic Signal Calibration** (https://www.luxalgo.com/library/concept/logistic-signal-calibration/): Logistic regression is the discriminative sibling: it learns weights that account for feature correlation, where naive Bayes counts each feature independently. Logistic needs more data and optimization; naive Bayes trains from counts and stays honest about what each input contributed.
- **Random Forest** (https://www.luxalgo.com/library/concept/random-forest/): A forest captures nonlinear interactions between features, exactly what the naive independence assumption discards, and pays with data hunger and opacity. Naive Bayes is the low-variance, high-bias end of the same spectrum: crude, stable, and inspectable.
- **kNN Analog Forecasting** (https://www.luxalgo.com/library/concept/knn-analog-forecasting/): kNN stores history and answers by similarity at query time, no training step, no distributional summary. The Bayesian classifier compresses history into priors and likelihood tables and discards the examples. Memory versus summary, with opposite scaling and staleness trade-offs.

## FAQ

### What does the naive in naive Bayes mean?

It refers to the assumption that features are conditionally independent given the class, which lets the joint likelihood be computed as a product of per-feature likelihoods. Real trading features are usually correlated, so the assumption is knowingly wrong. The classifier can still rank outcomes well despite this, but its probabilities are typically overconfident and should not be read as exact odds.

### Can a Bayesian classifier tell me my probability of winning a trade?

Not literally. The posterior is fitted from historical feature-outcome pairs, so it reflects the training window, the label definition, and the independence assumption baked into the model. Correlated features and shifting regimes routinely miscalibrate it. Use the output to rank setups and set entry thresholds, then validate on out-of-sample data before trusting any stated probability.

### Should features be discretized or left continuous?

Both work, differently. Discretizing into bins, oscillator zones, sign flags, quantile buckets, produces counting tables that are robust, chart-friendly and assumption-light, at the cost of losing within-bin information. Gaussian naive Bayes keeps features continuous but assumes each is roughly normal within a class, which fat-tailed market features often violate. Binned versions dominate on-chart implementations because counting is cheap and honest.

### How much data does naive Bayes need?

Less than most alternatives, which is its quiet superpower. Each likelihood estimate only needs enough examples per class per bin to count reliably, so a few hundred labeled bars can produce a usable model where a neural network would memorize noise. The floor still exists: rare bins and rare classes estimate badly, and smoothing corrections for zero counts are standard practice.

### Why do naive Bayes posteriors pin near 0 or 1?

Correlated evidence gets counted repeatedly. When five features all echo the same underlying condition, the independence assumption multiplies five likelihood ratios where honest accounting would apply one, compounding the odds far beyond what the evidence supports. The ranking usually survives this inflation; the calibration does not, which is why thresholds are set empirically and outputs pass through a calibration map before being read as odds.

### Can a Bayesian classifier run directly on a chart?

Comfortably, and it is one of the few learned models that can. The whole model is a set of counting tables and class frequencies, updateable in place as bars close and small enough for script arrays, which is how on-chart implementations like the naive Bayes order-flow study work. The same lightness imposes the usual honesty requirements: causal labels, no lookahead in the features, and out-of-sample checks before the posterior earns real risk.

## Related concepts

- Kernel Regression: https://www.luxalgo.com/library/concept/kernel-regression/
- Gaussian Process Regression: https://www.luxalgo.com/library/concept/gaussian-process-regression/
- Kernel Density Estimation: https://www.luxalgo.com/library/concept/kernel-density-estimation/
- Support Vector Machines: https://www.luxalgo.com/library/concept/support-vector-machines/
- Decision Trees: https://www.luxalgo.com/library/concept/decision-trees/
- Gradient Boosting: https://www.luxalgo.com/library/concept/gradient-boosting/
- Random Forest: https://www.luxalgo.com/library/concept/random-forest/
- Neural Networks: https://www.luxalgo.com/library/concept/neural-networks/
- LSTM / Recurrent Networks: https://www.luxalgo.com/library/concept/lstm-recurrent-networks/
- Self-organizing Maps: https://www.luxalgo.com/library/concept/self-organizing-maps/

---

Source: https://www.luxalgo.com/library/concept/bayesian-classifiers/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/