A probabilistic neural network (PNN) is a classifier that estimates how densely each class packs the space around a new input, then picks the class with the highest density. It has four layers and one setting to tune, the smoothing width sigma, and its training step is storing the data. Donald Specht described it in a 1988 conference paper as a network whose decisions approach the Bayes optimal under certain conditions, meaning the lowest error rate any classifier could reach on that data.
This guide covers how the layers work, how sigma behaves, a working version in Python with the numerical bug that breaks most first attempts, and when a PNN is still the right tool.
How a probabilistic neural network works
The plain version: put a small bell curve on every training example, add up the curves for each class, and see which class's pile is tallest where the new point lands.
That pile of bell curves is a kernel density estimate, also called a Parzen window estimate. The scikit-learn guide to density estimation describes it as each point contributing a Gaussian curve to the total, which produces a smooth estimate of where the data lives. A PNN builds one of these estimates per class, then applies Bayes' rule: given equal priors, the class with the highest density at the input is the most probable one.
Specht's insight, laid out in his 1988 IEEE paper on probabilistic neural networks, was that this statistical method maps neatly onto a neural network. Replace the sigmoid activation with an exponential one and the network computes nonlinear decision boundaries. The same paper notes that new data can update the boundaries in real time, because adding an example means adding a set of weights equal to it.
So a PNN is a neural network in structure and a kernel density classifier in behaviour. Statisticians and neural network researchers can each claim it, and both have been politely doing so since the late eighties.
The four PNN layers, and how to determine input layers
Every PNN has the same four layers. Their sizes come straight from the data, so there is no architecture search to run. That may be the most relaxing sentence in machine learning.
| Layer | Size | What it does |
|---|---|---|
| Input | One neuron per feature | Passes the scaled feature values forward |
| Pattern | One neuron per training example | Computes a Gaussian of the distance to its stored example |
| Summation | One neuron per class | Averages the pattern outputs belonging to its class |
| Output | One decision | Picks the class with the largest sum |
How to determine input layers in a neural network of this kind is the easy part: count your features. Four measurements per flower means four input neurons. Categorical features need encoding first, since the network only understands distances between numbers.
The step that decides success is scaling. The pattern layer measures Euclidean distance, so a feature measured in thousands drowns out one measured in fractions. Standardise every feature to zero mean and unit variance before anything else, or the network will classify mostly on whichever column happens to have the biggest units.
The pattern layer is where the memory cost hides. A training set of 50,000 rows produces 50,000 pattern neurons, each one consulted on every prediction.
Sigma, and why a PNN has no delta to train
What is the delta in neural networks? In a standard network trained by backpropagation, the delta is the error signal for a neuron: how much the loss changes as that neuron's input changes. Training repeats the delta calculation thousands of times while the weights inch toward a better answer.
A PNN skips all of it. There is no loss to minimise and no delta to propagate, because the weights are the training examples themselves. The only free parameter is sigma, the width of each bell curve, which MathWorks calls the spread.
Sigma controls the trade-off. The MathWorks newpnn documentation puts it this way: near zero, the network acts as a nearest-neighbour classifier; larger values let several nearby examples vote. Here is what that looked like when we ran the Python version below on two scikit-learn datasets, standardised, with a 70/30 split:
| Sigma | Iris test accuracy | Breast cancer test accuracy |
|---|---|---|
| 0.01 | 95.6% | 94.7% |
| 0.3 | 97.8% | 94.7% |
| 1 | 84.4% | 95.3% |
| 5 | 82.2% | 91.8% |
At sigma 0.01, both results matched a 1-nearest-neighbour classifier exactly, as the documentation predicts. Push sigma too high and every class's curve flattens into the same broad hill. The best sigma differed by dataset, so tune it with cross-validation on a held-out split. For a refresher on reading those scores, see our guide to the classification report in deep learning.
A probabilistic neural network in Python
The whole network fits in a short class. This version works in log space, and the reason follows the code.
import numpy as np
from scipy.special import logsumexp
class PNN:
def __init__(self, sigma=0.5):
self.sigma = sigma
def fit(self, X, y):
# Training is storage: one pattern neuron per example.
self.X, self.y = np.asarray(X, float), np.asarray(y)
self.classes = np.unique(self.y)
return self
def _log_scores(self, X):
d2 = ((np.asarray(X, float)[:, None, :] - self.X[None]) ** 2).sum(-1)
log_k = -d2 / (2 * self.sigma ** 2)
return np.stack([logsumexp(log_k[:, self.y == c], axis=1)
- np.log((self.y == c).sum())
for c in self.classes], axis=1)
def predict(self, X):
return self.classes[self._log_scores(X).argmax(axis=1)]
Our first version computed the bell curves directly with np.exp. On the breast cancer data at sigma 0.01, it scored 37.4% accuracy. The cause was underflow. With 30 features and a narrow kernel, every exponential rounded to exactly zero, so all 171 test rows scored zero for both classes. Faced with a tie, argmax quietly returned the first class every time. 37.4% is the share of that class in the test set, so the model had become a very confident coin with one face.
Taking logs and combining them with logsumexp keeps the numbers in range. Same data, same sigma, 94.7%. If you need probabilities, exponentiate the log scores and normalise each row. If your neural network in Python ever reports an accuracy equal to a class's share of the data, check for this before anything else.
When to use a PNN: classification boundaries and cost
A PNN suits small to medium tabular datasets where you want class probability estimates and near-zero training time. At its best sigma, it matched a small scikit-learn MLP with one hidden layer of 32 units on both datasets: 97.8% on iris and 95.3% on breast cancer. Fitting the PNN took microseconds; the MLP needed around a tenth of a second and a learning loop.
To see what the network has learned, plot its classification boundary. Build a grid over two features with np.meshgrid and call predict on every grid point. Then draw the result with matplotlib's contourf. Small sigma gives jagged islands around single examples; larger sigma gives smooth curves. The picture explains a sigma choice faster than any table.
PNNs also sidestep a classic problem. Overcoming catastrophic forgetting in neural networks, where training on new data erases what the network learned before, is an active research area for backpropagation models. A PNN learns a new example by adding one pattern neuron, and nothing already stored changes.
The bill arrives at prediction time. Every query is compared with every stored example, so cost grows with the training set. In our test, classifying 100 points against 20,000 stored examples with 30 features took 0.17 seconds on a laptop, fine for a batch job and slow for a busy API. MathWorks has also marked its newpnn function for removal in a future MATLAB release, steering users toward its modern network functions.
Use this rule of thumb: reach for a PNN when numeric, well-scaled data fits in memory and you want a strong baseline in minutes. For large datasets and unstructured inputs like images, train a deep network. The neural network recipes guide covers that path, and LLM Systems Engineering goes deep on training models at scale.