A neural network predicts by passing numbers through a sequence of functions called layers. During training, it compares a prediction with a target, measures the error, and adjusts the numbers inside those functions. Once trained, it can make a prediction without knowing the target. A decision tree can answer the same question, but it gets there by following branches instead of combining weighted inputs.
What happens in a forward pass?
Imagine a service that estimates how much CPU time a batch job will use. The caller supplies a feature, such as the number of records measured in thousands; the service returns a number of seconds. A feedforward network works like a chain of function calls: each layer takes the previous layer’s output as its input. The analogy stops at the implementation. You choose the operations, but training determines the weights, so reading the code alone won’t tell you the prediction.
A weight scales an input; a bias adds an offset. A hidden layer computes intermediate values rather than returning them to the caller. Its activation function can bend the input-output relationship: without a nonlinear step, stacking weighted sums and offsets still produces just one weighted sum and offset. In an image model, a hidden layer can learn a useful combination of neighboring pixel values instead of requiring a developer to specify every visual feature. The pixels still need a consistent numerical representation. See how activation functions change a layer’s output for the alternatives.
One training step, from prediction to new weights
Use one synthetic job: 2 thousand records (x = 2), with an observed CPU time of 2 seconds. Give the network one hidden unit, two trainable weights, and no biases. The first weight starts at w = 0.5; the second at v = 1. The hidden unit keeps positive values and replaces negative ones with zero.
Forward: The hidden value is h = max(0, w × x) = 1. The output is v × h = 1 second. Loss: Score the miss with half the squared error: 0.5 × (1 − 2)² = 0.5. Unlike a pass/fail assertion, this score distinguishes a near miss from a much larger error.
Backward: A gradient tells us how fast the loss changes locally with a weight. Start with the prediction error, −1. For the output weight, multiply by the hidden value: dv = −1 × 1 = −1. For the first weight, follow the path back through the output weight, the active hidden unit (slope 1), and the input: dw = −1 × 1 × 1 × 2 = −2. This use of the chain rule is backpropagation. It computes the gradients; the optimizer uses them to change the weights.
Update: Subtract 0.1 times each gradient from its original weight. That gives w = 0.7 and v = 1.1. A second forward pass predicts 1.54 seconds, and the loss drops to 0.1058. The learning rate, 0.1, sets the size of the step. A negative gradient calls for increasing the weight, not decreasing it.
Run this in Python 3; no packages or downloads are needed:
x, target = 2.0, 2.0
w, v, rate = 0.5, 1.0, 0.1
h = max(0.0, w * x)
y = v * h
error = y - target
dv = error * h
dw = error * v * x if w * x > 0 else 0.0
print(f"before: prediction={y:.2f}, loss={0.5 * error**2:.4f}")
w, v = w - rate * dw, v - rate * dv
y = v * max(0.0, w * x)
print(f"after: w={w:.2f}, v={v:.2f}, prediction={y:.2f}, loss={0.5 * (y - target)**2:.4f}")In a real training run, repeat the process over batches of examples. During inference (serving a prediction), run only the forward calculation with the saved weights. For the same workflow using library operations, see implementing neural networks in PyTorch and TensorFlow.
What would a decision tree predict for the same job?
Suppose two recorded jobs took 2 seconds for 2 thousand records and 4 seconds for 4 thousand. A depth-one regression tree can separate those observations at 3 thousand: at or below the threshold return 2 seconds; above it return 4. Its prediction is the mean recorded time in the selected leaf. For a new job with 2.5 thousand records, that tree still predicts 2 seconds. The network after our single update predicts 1.1 × (0.7 × 2.5) = 1.925 seconds.
The difference is in the shape of the rule: the tree holds its prediction constant until a threshold is crossed, while the network changes with the input on this active segment. The tree saw two jobs and the network took one step on one job; neither number tells us which model is more accurate on new jobs. If you need to explain a small set of thresholds to an operator, start with a shallow tree. Compare it with a network on identical training and held-out jobs before accepting the extra complexity. For other baselines, see how common machine learning algorithms compare.
What a lower loss does not tell you
One improved prediction shows that the update helped on that example, not that record count determines CPU time. A new file format or a different processor can break the relationship. Test on later jobs kept out of training; report typical and worst misses in seconds. A tree can memorize tiny groups, and a network can fit noise. Neither recovers information that was never recorded.
Neural networks do not automatically make unlabeled data useful: our runtime predictor needs recorded times. A self-supervised model instead constructs targets from the input. Larger networks can learn richer features, but require more computation, and an early layer can receive too small a gradient to learn much. If the output layer changes while earlier layers barely move, see when vanishing gradients occur.
Sources and further reading
For the layer calculation, see Google’s interactive lesson on nodes and hidden layers. The PyTorch guide to automatic differentiation connects the forward calculation to the backward pass. The scikit-learn decision tree guide explains regression leaves and split criteria.
As an Amazon Associate I earn from qualifying purchases. For a textbook treatment of feedforward networks, see Deep Learning by Ian Goodfellow, Yoshua Bengio, and Aaron Courville (Amazon US).



