Machine Learning Algorithms

Chapter 12
Neural Networks and Deep Learning

Post Graduate Program in Business Analytics
Machine Learning Algorithms   •   Post Graduate

Neural Networks and Deep Learning

Introduction and context

Neural networks are computational models that learn relationships between inputs and outputs by composing many parameterised transformations. Their modern importance arises from three developments: large datasets, specialised hardware such as GPUs, and optimisation methods capable of training models with millions or billions of parameters. In business analytics, neural networks support demand forecasting, fraud detection, recommendation, computer vision, speech analysis, customer-service automation and document intelligence.

A neural network is not automatically superior to a statistical or tree-based model. Its value depends on the structure of the data, the volume of observations, the cost of errors, the need for interpretability and the operational environment. Deep learning is especially effective when the problem involves unstructured or high-dimensional data, such as images, language, audio and event sequences.

Learning objectives

After studying this chapter, the reader should be able to:

  1. Explain perceptrons and multilayer feed-forward networks.
  2. Describe activation functions, loss functions and gradient-based learning.
  3. Derive the essential steps of backpropagation.
  4. Compare optimisation and regularisation methods.
  5. Distinguish convolutional, recurrent and transformer architectures.
  6. Select suitable neural architectures for business problems.
  7. Evaluate neural systems using technical, business, ethical and governance criteria.

1. The perceptron: the basic computational unit

A perceptron receives an input vector x = (x1, x2, …, xd), assigns a weight to each feature, adds a bias, and applies an activation function. Its pre-activation is

z = wᵀx + b = ∑j=1d wj xj + b

Here, w is the weight vector, b is the bias, and d is the number of input features. The bias permits the decision boundary to move away from the origin. For binary classification, the original perceptron uses a step function:

ŷ = { 1, if z ≥ 0; 0, if z < 0 }

The perceptron can represent a linear decision boundary. For two inputs, the boundary is w1x1 + w2x2 + b = 0. It cannot represent non-linearly separable relationships such as XOR using a single unit. This limitation motivated multilayer networks.

A perceptron learning update for an observation is commonly written as

w ← w + η(y − ŷ)x,
b ← b + η(y − ŷ)

where y is the target, ŷ is the prediction and η > 0 is the learning rate. The classic convergence result applies only when the training data are linearly separable and the learning rate is positive; it does not guarantee success on non-separable data.

2. Multilayer feed-forward networks

A multilayer perceptron (MLP) stacks layers of units. A typical network contains an input layer, one or more hidden layers and an output layer. Each layer transforms its input:

h^(ℓ) = φ^(ℓ)(W^(ℓ)h^(ℓ−1) + b^(ℓ))

where h^(ℓ−1) is the previous layer’s output, W^(ℓ) is a weight matrix, b^(ℓ) is a bias vector and φ^(ℓ) is applied element by element. The input is h^(0) = x. A network is called feed-forward when information moves from input to output without cycles.

The hidden layers allow the model to construct nonlinear representations. The universal approximation theorem states, under specific technical assumptions, that a sufficiently wide network with a suitable non-constant activation can approximate broad classes of continuous functions on compact domains. This is an existence result, not a guarantee that training will be efficient, that the required network will be small, or that the learned function will generalise.

For a regression output, the final activation is often linear, ŷ = z. For binary classification, a sigmoid output is used:

σ(z) = 1/(1 + e^(−z))

It represents an estimated probability when trained appropriately. For mutually exclusive K-class classification, the softmax function is

softmax(z)k = e^(zk) / ∑j=1K e^(zj)

The outputs are non-negative and sum to one. Softmax probabilities should not automatically be interpreted as perfectly calibrated probabilities.

3. Activation functions

Activation functions introduce nonlinearity. Without them, a composition of linear transformations is still linear, regardless of the number of layers.

FunctionDefinition or behaviourStrengthLimitation
Sigmoid1/(1+e^(−z))Bounded probability-like outputSaturating gradients; non-zero-centred
Tanh(ez−e^(−z))/(ez+e^(−z))Zero-centred hidden representationSaturation at large magnitudes
ReLUmax(0,z)Simple, fast, useful gradients for positive inputsDead units for persistently negative inputs
Leaky ReLUmax(αz,z), with small α > 0Reduces dead-unit problemExtra hyperparameter; still unbounded
GELUSmoothly gates inputs according to their magnitudeEffective in many transformer modelsMore computationally involved

For binary classification with a sigmoid output, binary cross-entropy is commonly used:

L = −[y log(p) + (1−y)log(1−p)]

Here y ∈ {0,1} is the target and p ∈ (0,1) is the predicted probability. For K-class one-hot targets, categorical cross-entropy is

L = −∑k=1K yk log(pk)

For regression, mean squared error is

MSE = (1/n)∑i=1n(yi − ŷi)2

where n is the number of observations. The loss should reflect the business cost of errors; it is not merely a technical default.

4. Backpropagation and gradient-based learning

Training adjusts parameters to minimise a loss over the training data. For parameters θ, gradient descent uses

θt+1 = θt − η ∇_θ J(θt)

where J is the objective function, ∇_θJ is its gradient and η is the learning rate. In practice, the gradient is estimated using a mini-batch rather than the entire dataset.

Backpropagation is an efficient application of the chain rule. Consider a two-layer network:

z^(1)=W^(1)x+b^(1), h^(1)=φ(z^(1))
z^(2)=W^(2)h^(1)+b^(2), ŷ=g(z^(2))

If L is the loss, the output-layer error is

δ^(2) = ∂L/∂z^(2)

The hidden-layer error is

δ^(1) = ((W^(2))ᵀδ^(2)) ⊙ φ′(z^(1))

where ⊙ denotes elementwise multiplication. Parameter gradients are

∂L/∂W^(2) = δ^(2)(h^(1))ᵀ,
∂L/∂b^(2)=δ^(2)

and

∂L/∂W^(1) = δ^(1)xᵀ,
∂L/∂b^(1)=δ^(1)

These expressions assume differentiable operations at the relevant points. ReLU is not differentiable at zero, but implementations assign a subgradient convention there.

Worked example: one gradient update

Suppose a single neuron has x=2, w=0.5, b=0, target y=3, and linear output ŷ=wx+b=1. Using squared loss L=½(ŷ−y)2,

∂L/∂ŷ = ŷ−y = −2. Therefore ∂L/∂w = (ŷ−y)x = −4 and ∂L/∂b = −2. With learning rate η=0.1,

wnew=0.5−0.1(−4)=0.9 and bnew=0−0.1(−2)=0.2. The updated prediction is 0.9×2+0.2=2.0, closer to the target 3. This is an illustrative single-observation update, not a complete training procedure.

5. Optimisation and generalisation

Optimisers

Stochastic gradient descent (SGD) updates parameters from randomly selected mini-batches. Momentum accumulates part of the previous update and can reduce oscillation. Adaptive methods such as Adam maintain moving estimates of first and second moments of gradients. Adam is often effective as a starting point, but its default settings are not universally optimal; learning-rate schedules, batch size and validation performance remain important.

Training loss usually decreases as a model learns the sample. Generalisation concerns performance on unseen data. A model that memorises training examples may have low training loss but poor validation or test performance.

Regularisation

L2 regularisation adds a penalty proportional to the squared parameter magnitudes:

Jreg(θ)=J(θ)+λ∑j θj²

where λ ≥ 0 controls the penalty. L1 regularisation uses λ∑j|θj| and may encourage exact zeros. The penalty convention varies: some definitions include one-half or apply regularisation only to weights, not biases. The convention must be stated when comparing coefficients.

Dropout randomly sets units to zero during training with probability q, then uses an appropriate scaling rule. It reduces reliance on particular internal pathways but changes the optimisation problem. Early stopping halts training when validation performance stops improving. Data augmentation creates plausible variations, such as image crops or noise, but must preserve the target relationship.

Batch normalisation and related normalisation methods can stabilise optimisation. They are not substitutes for sound data preparation, leakage control or validation design. Hyperparameters must be selected using training and validation data; the test set should be reserved for final unbiased assessment.

6. Convolutional neural networks

Convolutional neural networks (CNNs) exploit local structure and parameter sharing. A two-dimensional cross-correlation, commonly called convolution in deep-learning software, can be represented as

S(i,j)=∑m∑n K(m,n)X(i+m,j+n)

where X is an input array, K is a kernel and S is a feature map. Stride controls the movement of the kernel; padding controls treatment of boundaries. If input size is N, kernel size F, padding P and stride St, the one-dimensional output size is

Nout = floor((N + 2P − F)/St) + 1

The formula assumes integer-compatible dimensions and a conventional discrete convolution layout.

Early CNN layers often detect edges or simple textures; deeper layers combine them into object-level patterns. Pooling or strided convolution reduces spatial resolution and computational cost, although excessive reduction can discard useful information. CNNs are effective for quality inspection, medical images, satellite imagery, retail shelf analysis and document images. Their limitations include sensitivity to distribution shifts, the need for labelled data and sometimes weak performance when long-range relationships dominate.

7. Recurrent and sequence architectures

Recurrent neural networks (RNNs) process observations sequentially while maintaining a hidden state:

ht = φ(Wxx xt + Whh ht−1 + bh)
yt = g(Wyh ht + by)

Here t indexes time, xt is the current input and ht is the state. Training through time can produce vanishing or exploding gradients because repeated Jacobian products may become very small or very large. Gradient clipping, gated units and careful initialisation can help.

Long short-term memory (LSTM) and gated recurrent unit (GRU) architectures introduce gates that regulate information retention and updating. They are useful for some time series, event logs and streaming applications. However, sequential computation limits parallelism, and long-range dependencies may remain difficult.

For business forecasting, a neural sequence model should be compared with seasonal benchmarks, exponential smoothing, ARIMA-type models and gradient-boosted trees. Time-based validation is essential: random splitting can allow future information to enter training and produce misleading results.

8. Attention and transformers

Attention allows a representation to combine information from different positions. Scaled dot-product attention is

Attention(Q,K,V)=softmax(QKᵀ/√dk)V

Q, K and V are query, key and value matrices, while dk is the key-vector dimension. Scaling by √dk helps control the magnitude of dot products and stabilise softmax gradients.

Multi-head attention runs several attention transformations in parallel, enabling different relational patterns. A transformer typically combines attention, position information, residual connections, normalisation and a position-wise feed-forward network. Unlike a basic RNN, it can process many sequence positions in parallel during training. Its principal cost is often quadratic in sequence length for full attention, making very long contexts expensive in memory and computation.

Transformers support language modelling, document classification, information extraction, code analysis, forecasting variants and multimodal systems. Pretraining on broad data followed by fine-tuning or prompting can reduce labelled-data requirements, but domain adaptation, factual reliability, privacy and evaluation remain major concerns. Retrieval-augmented generation can provide access to enterprise documents, but retrieval quality, access controls and citation verification are necessary.

9. Choosing an architecture for business analytics

Architecture selection should begin with the data-generating process and decision objective, not with a preference for fashionable models.

Problem characteristicCandidate architectureImportant comparison
Tabular customer or credit dataMLP, boosted trees, linear modelsTrees may be stronger with moderate data and mixed features
Images or spatial gridsCNN, vision transformerData volume, latency and shift robustness
Short or medium sequencesRNN, temporal CNN, transformerAccuracy, latency and parallelism
Long documents or languageTransformerCost, privacy, hallucination and retrieval
Streaming stateful eventsRNN, temporal model, online alternativesMemory, drift and update frequency

A practical evaluation should include predictive metrics and business measures. Classification may use precision, recall, F1, ROC-AUC or precision-recall AUC; regression may use MAE, RMSE or a cost-weighted loss. For a model producing a probability pi, calibration can be assessed by comparing predicted probabilities with observed event frequencies. Threshold selection should reflect capacity constraints and asymmetric costs rather than defaulting to 0.5.

10. Illustrative case: retail demand and inventory risk

Background and problem

A fictional omnichannel retailer sells thousands of products across stores and an online channel. Stockouts reduce revenue and customer loyalty, while overstock creates markdowns. The retailer wants seven-day forecasts and an alert for products likely to stock out.

Analysis

Available data include sales history, prices, promotions, inventory, store attributes, holidays, weather and product descriptions. A naïve random split would be inappropriate because it could train on future promotional regimes. The analytics team uses rolling-origin validation: each training window precedes its validation window chronologically.

Approach and solution

The team establishes seasonal naïve and gradient-boosted-tree baselines. A temporal model receives sequences of sales, prices and inventory, while static product and store features are encoded separately. A CNN or temporal convolution may capture local demand patterns; an attention-based model may capture relationships across products and locations. The final choice is made using a cost-weighted objective that penalises stockout errors more heavily than small over-forecasting errors.

Data leakage controls exclude future inventory corrections and post-period sales adjustments. Promotions are represented using information known at forecast time. The model is calibrated for stockout probabilities, and a decision rule sends alerts only when expected lost-margin reduction exceeds the operational cost of intervention.

Outcome and governance

In this illustrative case, the neural model improves forecast accuracy for products with rich historical data, but the boosted-tree baseline performs better for sparse new products. The retailer therefore deploys a segmented strategy: the neural model for high-volume products, a simpler model for sparse products and a cold-start rule based on product similarity. Monitoring tracks error by product class, location and promotion type, as well as drift and alert volume.

Learning points

The case demonstrates that architecture choice, temporal validation, cost-sensitive evaluation and operational integration matter as much as model capacity. A technically accurate model can still fail if its inputs are unavailable at decision time or if managers cannot act on its outputs.

11. Limitations, ethics and governance

Neural networks can be opaque, sensitive to data quality and computationally expensive. They may reproduce historical discrimination, infer sensitive attributes, leak confidential information or fail unpredictably under distribution shift. Generative systems may produce plausible but false content. Adversarial examples and data poisoning create additional security risks.

Governance should include documented data provenance, lawful purpose, access control, retention limits, reproducible training, model cards or equivalent documentation, human oversight and incident procedures. High-impact decisions require fairness analysis across relevant groups, explanation appropriate to the user, appeal mechanisms and monitoring after deployment. Explainability methods such as feature attribution or counterfactual analysis are aids to investigation, not proofs of causal reasoning.

Privacy-preserving approaches may include minimisation, aggregation, differential privacy or federated learning, but each introduces trade-offs in accuracy, complexity and protection. Regulatory obligations vary by jurisdiction and application; organisations must obtain current legal advice rather than treating a technical checklist as compliance.

12. Contemporary developments and best practices

Current practice includes transfer learning, self-supervised pretraining, foundation models, parameter-efficient fine-tuning, knowledge distillation, sparse or mixture-of-experts models and multimodal learning. These methods can reduce training cost or improve performance, but they also increase dependency on data provenance, vendor controls and evaluation discipline.

Best practices include:

  • define the decision, loss and cost of errors before selecting an architecture;
  • establish simple, strong baselines;
  • prevent temporal, target and group leakage;
  • standardise inputs using training data only;
  • use validation procedures aligned with deployment;
  • tune learning rate, batch size, capacity and regularisation systematically;
  • monitor calibration, subgroup performance, drift, latency and resource use;
  • version data, code, parameters and evaluation results;
  • test failure modes and out-of-distribution behaviour;
  • provide rollback, human review and post-deployment monitoring.

Chapter Summary

Neural networks learn layered transformations through weighted sums, nonlinear activations and optimisation of a loss function. A perceptron provides a linear decision boundary; multilayer networks represent nonlinear functions. Backpropagation efficiently applies the chain rule, while SGD and adaptive optimisers update parameters. Activation functions, loss functions, regularisation and validation design strongly affect learning and generalisation.

CNNs exploit local spatial structure, RNNs maintain sequential state, and transformers use attention to model relationships across positions with substantial parallelism. Each architecture has benefits and limitations. Business deployment requires comparison with simpler baselines, appropriate metrics, temporal and subgroup validation, interpretability, privacy, security and operational monitoring. Deep learning is therefore not merely a modelling technique but a governed decision system.

Key Terms

Perceptron: A weighted computational unit with a bias and activation function.

Bias: A trainable intercept that shifts a neuron’s pre-activation.

Activation function: A nonlinear transformation applied by a neural unit.

Multilayer perceptron: A feed-forward network with one or more hidden layers.

Forward pass: Computation from inputs to predictions.

Loss function: A numerical measure of prediction error.

Backpropagation: Efficient gradient computation using the chain rule.

Gradient descent: Iterative parameter optimisation in the negative-gradient direction.

Epoch: One complete pass through the training dataset.

Mini-batch: A subset of observations used for one parameter update.

Regularisation: A method that discourages overfitting.

Dropout: Random omission of units during training.

Convolution: A local, shared-weight operation producing feature maps.

Recurrent neural network: A sequence model with a state updated over time.

LSTM: A gated recurrent architecture designed to retain information over intervals.

Attention: A weighted mechanism for combining representations at different positions.

Transformer: An architecture centred on attention, residual pathways and feed-forward layers.

Calibration: Agreement between predicted probabilities and observed frequencies.

Distribution shift: Change in the relationship or distribution between training and deployment data.

Transfer learning: Reusing knowledge learned from one task or dataset for another.

Review Questions

Short Answer Questions

  1. Why can a single perceptron not represent XOR?
  2. What role does the activation function play in a multilayer network?
  3. Define backpropagation and explain why it is computationally useful.
  4. State one benefit and one limitation of convolutional neural networks.
  5. Why is random train-test splitting dangerous for time-series forecasting?

Long Answer Questions

  1. Explain the architecture and training of a multilayer perceptron, including forward propagation, loss and gradient descent.
  2. Compare sigmoid, tanh, ReLU and GELU in terms of shape, gradient behaviour and typical use.
  3. Discuss overfitting in deep learning and evaluate L2 regularisation, dropout, early stopping and data augmentation.
  4. Compare CNNs, RNNs and transformers for business data, considering structure, computation and deployment constraints.
  5. Explain how privacy, fairness, security and human oversight should influence neural-network governance.

Analytical / Application Questions

  1. A bank has a moderately sized tabular dataset for default prediction and a very strict explanation requirement. Design an evaluation plan comparing logistic regression, boosted trees and an MLP. Justify metrics, validation and deployment criteria.
  2. A retailer reports excellent random-split forecasting accuracy but poor live performance after a promotion change. Diagnose possible causes and propose a time-aware redesign.
  3. A customer-service transformer produces fluent but unsupported answers from internal documents. Propose controls covering retrieval, access permissions, evaluation, human review and incident response.

Multiple Choice Questions with Answers

Question 1

Which limitation applies directly to a single perceptron?

A. It cannot learn any numerical weights

B. It can represent only a linear decision boundary

C. It always requires convolution

D. It cannot use a bias term

Correct Answer: B. It can represent only a linear decision boundary

Question 2

Which activation is most commonly associated with the transformation max(0,z)?

A. Sigmoid

B. Tanh

C. ReLU

D. Softmax

Correct Answer: C. ReLU

Question 3

In gradient descent, parameters are updated in which direction?

A. The positive-gradient direction

B. The negative-gradient direction

C. A random direction independent of the loss

D. The direction of largest parameter magnitude

Correct Answer: B. The negative-gradient direction

Question 4

What is the principal purpose of backpropagation?

A. To calculate gradients efficiently

B. To remove all hidden layers

C. To convert regression into classification

D. To guarantee zero test error

Correct Answer: A. To calculate gradients efficiently

Question 5

Which architecture explicitly exploits local spatial patterns and parameter sharing?

A. CNN

B. Basic RNN

C. Decision tree

D. Naïve Bayes classifier

Correct Answer: A. CNN

Question 6

Why does full self-attention become expensive for very long sequences?

A. It cannot represent token relationships

B. Its usual interaction matrix grows quadratically with sequence length

C. It requires labels for every token

D. It uses no matrix multiplication

Correct Answer: B. Its usual interaction matrix grows quadratically with sequence length

Question 7

For a binary classifier trained with a sigmoid output, which loss is commonly appropriate?

A. Binary cross-entropy

B. Cosine distance only

C. Unnormalised variance only

D. Poisson deviance in every case

Correct Answer: A. Binary cross-entropy

Question 8

If N=10, F=3, P=1 and St=1, what is the one-dimensional convolution output size?

A. 7

B. 8

C. 9

D. 10

Correct Answer: C. 9

Question 9

Which validation design is most appropriate for a forecasting problem?

A. Randomly shuffle all timestamps

B. Use future observations to impute the training period

C. Use chronological or rolling-origin validation

D. Evaluate only on the training data

Correct Answer: C. Use chronological or rolling-origin validation

Question 10

What does L2 regularisation generally encourage?

A. Larger parameter magnitudes

B. Smaller parameter magnitudes

C. Removal of the loss function

D. Perfect probability calibration

Correct Answer: B. Smaller parameter magnitudes

Machine Learning Algorithms
Chapter 12 of 15