A neural network is a model that learns a pattern from examples by adjusting many small numbers, called weights, until its predictions fit the data. This guide explains how that works in plain English, when a neural network is a sensible choice for business data, and when a simpler model does the job. It includes a short example we ran on two public datasets, with the code and the real output.
What Are Neural Networks?
A neural network is a prediction model built from layers of simple units called neurons. Each neuron takes numbers in, multiplies each by a weight, adds them up, and passes the result through a simple function. The name comes from a loose resemblance to brain cells. It is a maths model, not a copy of a brain.
A network has three kinds of layers. The input layer receives your data, one neuron per column. One or more hidden layers in the middle transform the numbers. The output layer gives the prediction, such as a price or a probability. The function applied inside each hidden neuron is called an activation function. A common one is ReLU, which simply replaces any negative number with zero. Stacking these steps lets the network model curved, non-linear relationships that a straight-line model cannot.
Training means showing the network examples with known answers. A loss function measures how wrong the predictions are. An algorithm called backpropagation works out how to nudge each weight to reduce that error. One full pass over the training data is an epoch. Training repeats for many epochs until the error stops improving.
Key Concept: Universal Approximation
A known theoretical result says that a network with one hidden layer and enough neurons can approximate any continuous function to a chosen accuracy. This says the network is flexible enough in principle. It does not say that training will find a good fit, or that you have enough data to find it.
Different data types use different network designs. Feedforward networks (plain layers, as described above) take rows of numbers. Convolutional neural networks (CNNs) are built for images. Recurrent networks (RNNs) and transformers are built for sequences such as text and, in some cases, time series.
When to Use Neural Networks
Neural networks are one tool among several. They tend to pay off in a few situations and often do not pay off in others.
They are a strong choice for unstructured data: images, audio, free text. Here there is no tidy table of columns, and networks can learn useful features directly from the raw input. They are also worth trying on large tables with many interacting variables, where simpler models leave a lot unexplained.
For ordinary tabular business data (rows of customers, orders or sessions, with a few dozen columns), the evidence is mixed. A 2022 benchmark by Grinsztajn, Oyallon and Varoquaux found that tree-based models, such as random forests and gradient boosting, stayed ahead of deep learning on medium-sized tabular datasets of around 10,000 samples. See "Why do tree-based models still outperform deep learning on tabular data?". The worked example below shows both outcomes on data we ran ourselves.
How Much Data Do You Need?
There is no fixed minimum. As a rule of thumb, small tables (a few hundred rows) rarely give a neural network room to beat a simple model, and the gap tends to open as rows grow into the thousands and beyond. The example below shows this directly. Images and text usually need far more examples, unless you start from a network that was already trained on a large dataset and adapt it to your task. That approach is called transfer learning.
When NOT to Use Neural Networks
Be cautious when you have a small dataset, need to explain each prediction to a regulator or customer, or have little computing time. Linear regression, random forests or gradient boosting are easier to explain and often score as well. Always compare against one of them before you commit.
Key Assumptions and Requirements
Data Assumptions
A network assumes the patterns in your training data will hold for new data. If you train on one customer segment or one season and apply the model somewhere else, accuracy can drop. Check that your training rows look like the rows you will predict on.
Rows should also be reasonably independent. If one customer appears many times, or rows are consecutive time points, a random train and test split lets information leak across the split. For time-ordered data, train on the earlier period and test on the later one.
Networks also need clean inputs. They do not cope with missing values on their own, so fill them in or remove them. Turn categories into numbers, for example with one-hot encoding (one 0/1 column per category).
Scaling Matters
When one column runs from 0 to 100 (age) and another from 0 to 1,000,000 (income), training can be slow or unstable, because the large column dominates the weight updates. The usual fix is standardization: subtract the column average and divide by the column spread, so each column is centered on zero. Our example below measures how much this matters.
Critical Preprocessing Steps
(1) Split the data into training and test sets first. (2) Fill or remove missing values. (3) Encode categories as numbers. (4) Fit the scaler on the training rows only, then apply the same scaler to the test rows. Fitting it on all rows leaks information from the test set. This mistake is called data leakage.
Computing Needs
Small networks on tables train in seconds on an ordinary laptop, as the example below shows. Large networks for images or text usually need a GPU (a graphics chip suited to this arithmetic) and can take hours or longer.
Practical Implementation Strategies
Step 1: Define the Prediction Task
Decide what you are predicting. A number such as revenue is regression. A category such as churn or not churn is classification. For regression, the output layer is usually one neuron with no activation and the loss is mean squared error. For a yes/no outcome, the output is one neuron with a sigmoid function (which squeezes any number into the range 0 to 1) and the loss is binary cross-entropy. For several classes, the output uses softmax and categorical cross-entropy.
Split your data into a training set (to learn from), a validation set (to tune settings and spot overfitting) and a test set (touched once, at the end). Common choices are 60 to 80 percent for training; these are conventions, not laws.
Step 2: Start Small
Begin with a small network: one or two hidden layers. A layout like the one below is a typical starting point for a yes/no prediction on a table. It is an illustration of the shape, not a tuned recommendation.
Illustrative layout for a yes/no prediction on a table:
Input layer: one neuron per column
Hidden layer 1: 64 neurons, ReLU activation, dropout
Hidden layer 2: 32 neurons, ReLU activation, dropout
Output layer: 1 neuron, sigmoid activation (a score from 0 to 1)
Dropout randomly switches off a share of neurons during each training step, which discourages the network from memorizing the training rows.
Step 3: Training Settings
The optimizer is the rule for updating weights. Adam is a widely used default. The learning rate is the size of each update: too large and training becomes unstable, too small and it crawls. Settings like these, chosen by you rather than learned from the data, are called hyperparameters. Tune them on the validation set, never on the test set. A batch size between 32 and 256 is a common starting point (rule of thumb).
Watch Training and Validation Error
Plot both. If training error keeps falling while validation error rises, the network is overfitting: it is memorizing the training rows instead of learning a pattern that carries over. Early stopping halts training when the validation error stops improving.
Step 4: Guard Against Overfitting
Besides dropout and early stopping, L2 regularization (also called weight decay) adds a penalty for large weights, which keeps the fit smoother. It is the same idea behind ridge regression. Data augmentation creates extra training examples by making small changes to existing ones, such as flipping or cropping an image. Getting more real data is usually the strongest fix.
Interpreting Results
Scores Are Not Always Probabilities
A classification network outputs a score between 0 and 1. That score is only a true probability if the model is calibrated, meaning that among all cases scored near 0.7, about 70 percent really are positive. Check this with a calibration plot. If it is off, methods such as Platt scaling or isotonic regression can correct it. Pick the cut-off for acting on a score from the business cost of a miss versus a false alarm, not from the default 0.5.
Which Inputs Matter?
Neural networks are often called black boxes, but you can still ask what drives their output. Permutation importance shuffles one column at a time and measures how much accuracy falls. A large fall means the model relied on that column. SHAP values (SHapley Additive exPlanations) split a single prediction into a contribution from each input. LIME is a related method that explains one prediction by fitting a simple model around it. These tools describe what the model uses. They do not show that changing an input would cause the outcome to change.
Judge the Model With the Right Metrics
For a number prediction, R-squared (R2) is the share of variation in the target that the model explains on data it has not seen. A value of 1 is perfect; 0 is no better than always predicting the average. For classification, precision is the share of predicted positives that are correct, and recall is the share of real positives that are caught.
On rare events, accuracy misleads. If 1 transaction in 100 is fraud, a model that says "not fraud" every time is 99 percent accurate and catches no fraud at all. Always compare a neural network with a simple baseline. If the baseline scores about the same, the simpler model is usually the better choice.
Common Pitfalls
- Data leakage. Any step that uses test rows before the final check, such as scaling on all rows, inflates your results.
- Overfitting. Large gap between training and validation scores. Use a smaller network, dropout, L2, early stopping, or more data.
- Underfitting. Poor scores on both. The network is too small or stopped too early.
- Tuning on the test set. Each time you look at test results and change something, the test set becomes part of training.
- Class imbalance. For rare outcomes, give the rare class a higher weight in the loss, or resample the data (for example with SMOTE, which creates synthetic rare-class rows).
Worked Example: Neural Network vs Simpler Models
We ran a small test on two public datasets that scikit-learn, a free Python library, provides. The diabetes set is bundled with it; the California housing set is downloaded on first use and then cached. The question: does a neural network beat a straight-line model and a gradient boosting model on tabular data, and does it matter how many rows there are?
- Diabetes: 442 patients, 10 measurements each, target is a disease-progression score one year later (bundled with scikit-learn).
- California housing: 20,640 census districts, 8 columns each, target is the median house value (bundled with scikit-learn; district-level census data).
For each dataset we used a random 75/25 train and test split (seed 42), trained three models on the training rows, and scored each on the test rows with R-squared. The network is a small MLPRegressor with two hidden layers (64 and 32 neurons), with early stopping. The code, as run (Python 3 with scikit-learn 1.8.0):
from sklearn.datasets import load_diabetes, fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.neural_network import MLPRegressor
from sklearn.metrics import r2_score
def mlp(scale=True):
net = MLPRegressor(hidden_layer_sizes=(64, 32), early_stopping=True,
max_iter=1000, random_state=42)
return make_pipeline(StandardScaler(), net) if scale else net
def compare(name, X, y, show_unscaled=False):
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.25, random_state=42)
print(f"{name}: {len(ytr)} train rows, {len(yte)} test rows")
models = {"Linear regression": make_pipeline(StandardScaler(), LinearRegression()),
"Gradient boosting": GradientBoostingRegressor(random_state=42),
"Neural network": mlp()}
if show_unscaled:
models["Neural network, no scaling"] = mlp(scale=False)
for label, m in models.items():
m.fit(Xtr, ytr)
print(f" {label:28s} test R2 = {r2_score(yte, m.predict(Xte)):.3f}")
d = load_diabetes()
compare("Diabetes (442 rows)", d.data, d.target)
c = fetch_california_housing()
compare("California housing (20,640 rows)", c.data, c.target, show_unscaled=True)
Output:
Diabetes (442 rows): 331 train rows, 111 test rows
Linear regression test R2 = 0.485
Gradient boosting test R2 = 0.424
Neural network test R2 = 0.426
California housing (20,640 rows): 15480 train rows, 5160 test rows
Linear regression test R2 = 0.591
Gradient boosting test R2 = 0.781
Neural network test R2 = 0.788
Neural network, no scaling test R2 = 0.534
| Model | Diabetes (331 train rows) test R2 | California housing (15,480 train rows) test R2 |
|---|---|---|
| Linear regression | 0.485 | 0.591 |
| Gradient boosting | 0.424 | 0.781 |
| Neural network (scaled inputs) | 0.426 | 0.788 |
| Neural network (no scaling) | not run | 0.534 |
What the numbers say
- Small data: the simplest model won. On 331 training rows, linear regression (0.485) beat both the neural network (0.426) and gradient boosting (0.424).
- Large data: the non-linear models pulled ahead. On 15,480 training rows, the network (0.788) and gradient boosting (0.781) were far above linear regression (0.591). The network and boosting differ by 0.007, which on a single split we would not call a real difference.
- Scaling mattered. The same network without standardized inputs scored 0.534 on California housing, below even linear regression, compared with 0.788 with scaling.
Limits. This is one random split and one seed per dataset, with no tuning, so the small gaps could change with another split. Two datasets do not show what happens on your data. The point is the pattern: check a simple baseline, and scale your inputs. To see how a given method behaves on your own file, upload a CSV and compare.
Best Practices for Production
- Track experiments and data versions. Record the settings, data and score of each model you train, so you can reproduce a result or roll back. Tools such as MLflow do this.
- Monitor after launch. Real-world patterns shift. Watch accuracy and the spread of incoming values, and retrain when they drift from the training data.
- Keep the baseline. Keep a simple model running alongside the network so you can see whether the extra complexity still pays.
- Check fairness. Compare error rates across groups of people before the model affects decisions about them. If a decision affects credit, jobs or health, people should be able to get an explanation of it.
Related Techniques
Gradient Boosting and Random Forests
For tables, gradient boosting and random forests are strong, quick to train, and easier to explain. In our California housing test, boosting came within 0.007 R-squared of the neural network.
Ensembles
An ensemble trains several models and averages their predictions. This often reduces variance, at the cost of more computing.
Transfer Learning
For images, text and audio, you can start from a network already trained on a large dataset and fine-tune it on your own smaller one. This reduces the amount of labeled data you need.
Your turn
Bring your own data and the question you actually need answered.
MCP AnalyticsData science by email Send us your data and your question, and we will reply. ds@mcpanalytics.ai
Frequently Asked Questions
What are neural networks and how do they work?
A neural network is a model made of layers of simple units. Each unit multiplies its inputs by weights, adds them up and applies a simple function. Training adjusts the weights to reduce prediction error, which lets the network learn non-linear patterns.
When should I use neural networks instead of traditional machine learning algorithms?
Consider them for images, audio and text, and for large tables with many interacting variables. For smaller tables, a linear model or tree-based model is often as good and easier to explain. Compare against one first.
How much data do I need to train a neural network effectively?
There is no fixed number. As a rule of thumb, a few hundred rows is too few for a network to beat a simple model, as our example showed with 331 training rows. With 15,480 training rows the network did well. Transfer learning reduces the data needed for images and text.
What are the most common mistakes when implementing neural networks?
Not scaling the inputs, leaking test data into training, overfitting, tuning on the test set and skipping a simple baseline. In our example, the same network scored 0.534 without scaling and 0.788 with it.
How can I interpret neural network predictions for business stakeholders?
Use permutation importance, SHAP values or LIME to show which inputs drive predictions, and show the score next to a simple baseline. These methods describe what the model uses; they do not prove that changing an input would change the outcome.
Glossary
| Term | Plain meaning |
|---|---|
| Weight | A number the network learns; it scales one input to one neuron. |
| Epoch | One full pass over the training data. |
| Overfitting | Fitting the training rows so closely that new rows are predicted poorly. |
| Hyperparameter | A setting you choose, such as learning rate or layer size. |
| R-squared (R2) | Share of variation in the target explained on unseen data. |
| Baseline | A simple model used as the bar the network must beat. |
Conclusion
Neural networks are a flexible tool. They are well suited to images, text and large tables. On small tables they often give no gain over a simple model, and on any table they need scaled inputs and a clean test. Start with a simple baseline, add a network only if it clearly scores better on data it has not seen, and keep a person responsible for the decision.
Sources
- Grinsztajn, L., Oyallon, E., Varoquaux, G. (2022). Why do tree-based models still outperform deep learning on tabular data? arXiv:2207.08815.
- scikit-learn documentation: California housing dataset (8 features, 20,640 samples, target in units of $100,000).
- scikit-learn documentation: MLPRegressor.