> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nimbusbci.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NimbusQDA

> NimbusQDA for Python: the Bayesian quadratic discriminant head with a class-specific covariance and Student-t predictive — for classes that differ in spread.

**Python**: `NimbusQDA` | **Julia**: `NimbusQDA`, a different implementation on RxInfer.jl — see the [Julia API reference](https://docs.nimbusbci.com/julia-sdk/api-reference.md#nimbusqda)\

**Mathematical model**: Normal-Inverse-Wishart posterior per class — its own mean and its own precision; Student-*t* predictive

`NimbusQDA` drops the one thing `NimbusLDA` assumes: that every class has the same covariance. Each class gets its own, so the decision boundary is quadratic and a class that is tight next to one that is diffuse is separated the way the data says it should be. It costs more trials to estimate, and the head is honest about that — with few trials the priors hold each covariance close to the pooled one.

> [!NOTE]
>
> **Python Personalizer head:** `Personalizer(head="qda")`, or `Personalizer.for_features(classes, head="qda")`; the P300 recipe `Personalizer.for_p300` builds on this family. On this head `fit_calibrated` fits a certificate. See [Trust & calibration](https://docs.nimbusbci.com/personalizer/trust-and-calibration.md).

## Quick start

```python theme={null}
from nimbus_bci import NimbusQDA

clf = NimbusQDA()                    # mu_scale=3.0
clf.fit(X_train, y_train)            # (n_trials, n_features)
labels = clf.predict(X_test)
probabilities = clf.predict_proba(X_test)
clf.partial_fit(X_new, y_new)        # conjugate update; no refit
```

sklearn-compatible, like every head: `make_pipeline(StandardScaler(), NimbusQDA())`, `cross_val_score`, `GridSearchCV`.

## When to use NimbusQDA

* The classes differ in variance as much as in mean — a P300 target response against a frequent non-target, where the classes overlap in amplitude but not in shape.
* Two-class problems with uneven class sizes; the per-class covariances are estimated separately, so the smaller class is not forced into the larger one's shape.
* You have enough trials per class for a covariance each — a few dozen is the practical floor.

## When not to use it

* **The classes share a covariance.** QDA then pays for flexibility it does not use and is the noisier estimate. Use [`NimbusLDA`](https://docs.nimbusbci.com/models/nimbuslda) — it is the default for a reason.
* **Few trials per class.** A covariance per class is many parameters; the head leans on its prior, and the boundary is closer to linear than the name suggests.
* **Non-Gaussian boundaries.** Use [`NimbusSoftmax`](https://docs.nimbusbci.com/models/nimbussoftmax).
* **A frozen trunk's embeddings with few trials.** Use [`NimbusProbit`](https://docs.nimbusbci.com/models/nimbusprobit).

## Model

Per class `k`, a Normal-Inverse-Wishart posterior over `(mu_k, W_k)`, and a class conditional `p(x | y = k) = N(mu_k, W_k⁻¹)`. Conjugate priors make the posterior closed-form and `partial_fit` an exact update. The predictive integrates over the posterior — a Student-*t* per class, not a plug-in Gaussian.

## Hyperparameters

| Parameter | Default | Meaning |
| - | - | - |
| `mu_loc` | `0.0` | Prior mean location for the class means; broadcast to every feature |
| `mu_scale` | `3.0` | Prior scale for the class means |
| `wishart_df` | `None` | Degrees of freedom of the per-class precision priors; `None` means `n_features + 2` |
| `class_prior_alpha` | `1.0` | Dirichlet smoothing on the class priors; higher is more uniform |
| `prior_fraction` | `None` | A data-scaled prior worth `prior_fraction * n` observations; scale-equivariant. `None` keeps the identity-scale prior |
| `forgetting` | `1.0` | Discount applied to the accumulated statistics on each `partial_fit`; `1.0` never forgets |
| `training_sfreq` | `None` | Sampling rate of the training data; persisted for the cross-session check |

`NimbusQDA` has no `kappa0`: the prior weight on the means is set through `mu_scale` or `prior_fraction`.

## The gate behind it

The fixed gate let nearly everything through: within a session on BNCI2015-001 it sent 83–99 % of the test trials with 19.6–36.5 % of all trials wrong commands, and the pinned accept rate sent 52–70 % with 14.4–26.1 % wrong (cell S22, read once). QDA's posteriors are confident more often than they are right, which is exactly the case a certificate is for.

```python theme={null}
p = Personalizer.for_features(classes, head="qda")
p.fit_calibrated(X_cal, y_cal, X_val, y_val)   # the risk gate at alpha 0.1
```

The risk gate kept wrong commands at 0.035–0.100 of all trials from 8 held-out trials per class on, sending 0.23–0.54 of the trials and none at all on 9 % of the draws; at 4 per class on two classes nothing is certified at alpha 0.1. Details: [Trust & calibration](https://docs.nimbusbci.com/personalizer/trust-and-calibration.md).

## Model inspection

```python theme={null}
params = clf.model_.params

for k, label in enumerate(clf.classes_):
    print(label, params["mu"][k])           # posterior class means

print(params["nu"], params["psi"].shape)    # the Wishart posterior
```

## Model selection context

| Head | Use it for |
| - | - |
| `NimbusQDA` | Classes with their own covariance; P300 |
| [`NimbusLDA`](https://docs.nimbusbci.com/models/nimbuslda) | The default; motor imagery; shared covariance |
| [`NimbusSoftmax`](https://docs.nimbusbci.com/models/nimbussoftmax) | Non-Gaussian multiclass boundaries (optional JAX) |
| [`NimbusProbit`](https://docs.nimbusbci.com/models/nimbusprobit) | Honest confidence on a few trials over many features |
| [`NimbusSTS`](https://docs.nimbusbci.com/models/nimbussts) | Non-stationary sessions and latent-state adaptation |

Head against head on the same corpora: [Evidence](https://docs.nimbusbci.com/personalizer/evidence.md#which-head-lda-vs-qda-vs-softmax).

## Next read

> [card] [Paradigms & profiles](https://docs.nimbusbci.com/personalizer/paradigms.md)
>
> The P300 recipe and session bundles.

> [card] [Trust & calibration](https://docs.nimbusbci.com/personalizer/trust-and-calibration.md)
>
> The certificate that decides in front of this head.

> [card] [sklearn Integration](https://docs.nimbusbci.com/python-sdk/sklearn-integration.md)
>
> Pipelines, cross-validation and tuning with the heads.

> [card] [Evidence](https://docs.nimbusbci.com/personalizer/evidence.md)
>
> QDA against LDA, Softmax and logistic regression.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.