## Why Build a Neural Network in Excel?
Imagine diving into machine learning without leaving your favorite spreadsheet app. That's right—Excel can handle neural networks! This approach democratizes ML, letting analysts, business pros, and hobbyists experiment with regressors using familiar tools like LAMBDA, MMULT, and array formulas. No need for Jupyter notebooks or heavy libraries; just pure Excel magic.
In this guide, we'll construct a neural network regressor from scratch. We'll use the classic Boston Housing dataset to predict house prices based on features like crime rate, rooms per dwelling, and accessibility to highways. By the end, you'll have a working model you can tweak and train yourself. Let's start simple and build up to advanced tweaks.
For the full working example, check out the [Excel file on GitHub](https://github.com/BlackArbsCEO/Excel-Neural-Network-Regressor/blob/main/Neural%20Network%20Regressor%20in%20Excel.xlsx?raw=true). The entire project is hosted at the [Excel Neural Network Regressor repo](https://github.com/BlackArbsCEO/Excel-Neural-Network-Regressor).
## Step 1: Prepare Your Data
Beginners, don't worry—this is straightforward. Load the Boston Housing dataset into Excel. It has 506 rows and 14 columns: 13 features (e.g., CRIM for crime rate, RM for average rooms, DIS for distance to employment centers) and MEDV (median house value) as the target.
- **Pro Tip**: Download a CSV version or paste it directly. Place features in columns A to M (rows 2-507) and targets in column N.
- Normalize the data! ML models love scaled inputs between 0 and 1. Use this LAMBDA formula for min-max normalization:
```excel
=LAMBDA(x, (x - MIN(x)) / (MAX(x) - MIN(x)))
```
Apply it across your feature columns. Name this function "Normalize" via Formulas > Name Manager. Your normalized data is now ready—call it with `Normalize(A2:M507)` spilled into a new range.
Real-world application: This mirrors preprocessing in any ML pipeline, preventing features with larger scales (like price) from dominating.
## Step 2: Design the Neural Network Architecture
Our network is simple yet powerful: one input layer (13 neurons), one hidden layer (10 neurons), and one output layer (1 neuron for regression).
- **Weights and Biases**: Randomly initialize them. For input-to-hidden weights (13x10 matrix), use `RANDARRAY(13,10)*2-1`. Do the same for hidden-to-output (10x1) and biases.
- Place these in dedicated sheets or ranges: e.g., Input-Hidden weights in P2:Y14, Hidden biases in AA2:AA11, etc.
Think of it like this: Each neuron is a weighted sum plus bias, passed through an activation function. Excel's MMULT handles matrix multiplication effortlessly.
## Step 3: Implement Forward Propagation
Here's where the fun begins. Forward prop computes predictions step-by-step.
### Hidden Layer Computation
For a batch of data (say, first 100 rows for training), calculate:
1. Input matrix: Normalized features, e.g., `A2:M101`.
2. Hidden pre-activation: `MMULT(inputs, input_hidden_weights) + hidden_biases` (spills as 100x10).
3. Apply ReLU activation: Custom LAMBDA for max(0, x).
```excel
=LAMBDA(z, IF(z>0, z, 0))
```
Name it "ReLU". Then: `ReLU(hidden_pre_act)`.
### Output Layer
Hidden outputs → `MMULT(hidden_outputs, hidden_output_weights) + output_bias`.
Apply a linear activation (none for regression) or sigmoid if needed.
Your predictions spill out—compare to actual MEDV (also normalized).
**Beginner Example**: Test with one sample. Input row 2 features, compute manually first to verify.
## Step 4: Define the Loss Function
Mean Squared Error (MSE) is king for regression:
```excel
=LAMBDA(y_true, y_pred, AVERAGE((y_true - y_pred)^2))
```
Name it "MSE". Compute `MSE(actuals, predictions)`—lower is better!
Advanced note: Track MSE over epochs to plot learning curves. Use Excel charts for visualization.
## Step 5: Backward Propagation and Training
Training updates weights via gradients. Excel simulates this with LAMBDA recursion.
### Key Gradients
- Output error: `(predictions - actuals)`.
- Delta output: As-is (linear).
- Hidden deltas: Backprop through ReLU (derivative is 1 if active, 0 else).
Custom LAMBDA for ReLU derivative:
```excel
=LAMBDA(z, IF(z>0, 1, 0))
```
Full backprop involves chain rule: gradients w.r.t. weights = outer product of inputs and deltas.
### Weight Updates
Use gradient descent: `new_weight = old_weight - learning_rate * gradient`.
Define a master training LAMBDA that orchestrates everything. It's recursive for epochs:
- Loop over batches.
- Forward pass.
- Compute loss.
- Backward pass.
- Update weights.
The article's genius is wrapping this in a single spillable function. Input your data range, epochs (e.g., 1000), learning rate (0.01), and watch it train!
**Practical Tip**: Batch size 32-64 for stability. Monitor for vanishing gradients—tweak activations if needed.
## Step 6: Evaluate and Predict
Post-training, compute R² score:
```excel
=LAMBDA(y_true, y_pred, 1 - SUM((y_true - y_pred)^2) / SUM((y_true - AVERAGE(y_true))^2))
```
Aim for 0.8+ on holdout data (rows 408-506). Plot predictions vs. actuals—Excel's scatter chart shines here.
Real-world: Use for quick prototyping. Predict new house prices by inputting features into the forward pass.
## Advanced Enhancements
Once comfy, level up:
- **More Layers**: Stack another hidden layer with MMULT chains.
- **Dropout**: Randomly zero neurons during training (LAMBDA with RANDARRAY).
- **Adam Optimizer**: Replace vanilla GD with momentum and RMSprop—formulas are implementable.
- **Hyperparameter Tuning**: Grid search learning rates (0.001-0.1) via Data Table.
**Code Snippet for Sigmoid (Alternative Activation)**:
```excel
=LAMBDA(z, 1 / (1 + EXP(-z)))
```
Derivative: `Sigmoid(z) * (1 - Sigmoid(z))`.
## Common Pitfalls and Fixes
- **#SPILL! Errors**: Clear ranges below formulas.
- **Slow Training**: Limit epochs or use smaller nets initially.
- **NaN Losses**: Clip gradients or normalize properly.
Excel's dynamic arrays (Office 365) are crucial—older versions struggle.
## Why This Matters
This isn't a toy; it's a gateway to understanding NNs deeply. Visualize weights as heatmaps (Conditional Formatting). Export to Power BI for dashboards. Businesses love it for no-code ML in reports.
Hands-on beats theory. Download the [GitHub repo](https://github.com/BlackArbsCEO/Excel-Neural-Network-Regressor), tweak, and share your improvements!
Total words: ~1150. Ready to Excel at ML?
---
<div style="text-align: center; margin-top: 2rem;">
<a href="https://towardsdatascience.com/the-machine-learning-advent-calendar-day-17-neural-network-regressor-in-excel/" target="_blank" rel="noopener noreferrer" class="view-full-resource-btn" style="display: inline-block; background-color: #f97316; color: white; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: 600; transition: background-color 0.2s;">View Full Resource</a>
</div>