luvv to helpDiscover the Best Free Online Tools
Topic 9 of 9

Neural Network Basics

Learn Neural Network Basics for free with explanations, exercises, and a quick test (for Data Scientist).

Published: January 1, 2026 | Updated: January 1, 2026

Why this matters

Neural networks power core Data Scientist tasks: classifying support tickets, predicting churn, ranking recommendations, extracting embeddings, and forecasting demand. Even if you later use advanced architectures, you will debug and improve them using these basics: how neurons compute, how losses and gradients work, and how to avoid overfitting.

  • Build a baseline classifier for a new dataset quickly.
  • Explain model behavior to stakeholders (which inputs matter and why).
  • Stabilize training when a deeper model fails (learning rate, normalization, activations).

Concept explained simply

A neural network is a stack of simple calculators (neurons). Each neuron computes a weighted sum of inputs plus a bias, then passes it through a squashing rule (activation function). Layers of these neurons learn patterns: early layers learn simple combinations, later layers learn complex ones.

Forward pass: inputs → weighted sums → activations → output. We compare output to ground truth using a loss function. Backpropagation computes how to nudge each weight to reduce loss. An optimizer (like SGD or Adam) applies those nudges repeatedly over the dataset.

Key terms (tap to expand)
  • Weights and bias: adjustable numbers the model learns.
  • Activation: non-linear function (ReLU, sigmoid, tanh, softmax).
  • Loss: how wrong the predictions are (e.g., cross-entropy, MSE).
  • Optimizer: algorithm updating weights (SGD, Momentum, Adam).
  • Epoch: one full pass over the training data.

Mental model

  • Weighted voting + squashing: inputs vote with strengths (weights), the neuron squashes the total to a usable signal.
  • Assembly line of feature makers: each layer refines features for the next layer.
  • Thermostat tuning: loss tells you how far off you are; gradients tell you which direction to turn the knobs (weights).

Core building blocks

  • Data and tensors: organize inputs as numeric arrays; keep shapes consistent (batch, features).
  • Initialization: small random weights help symmetry breaking; biases often start at zero.
  • Activations: ReLU/Leaky ReLU (fast, common), sigmoid (binary output), softmax (multi-class output), tanh (zero-centered).
  • Losses: binary cross-entropy (binary classification), categorical cross-entropy (multi-class), MSE (regression).
  • Optimizers: SGD (simple), Momentum/Nesterov (faster valleys), Adam (adaptive learning rates, strong default).
  • Regularization: L2 weight decay, dropout, early stopping, data augmentation.
  • Evaluation: use a validation set; measure accuracy/precision/recall/AUC for classification, MAE/MSE for regression.

Worked examples

Example 1: Single neuron (binary classification)

Neuron output: y = sigmoid(w·x + b). Suppose x = [2, -1], w = [0.6, 0.8], b = -0.2.

  • Weighted sum: 0.6*2 + 0.8*(-1) - 0.2 = 1.2 - 0.8 - 0.2 = 0.2
  • Sigmoid(0.2) ≈ 0.5498 → predicted probability ≈ 0.55
Example 2: Tiny 2-2-1 network (ReLU → Sigmoid)

x = [0.5, -1.0]. Hidden layer (ReLU): W1 = [[1.0, -2.0],[0.5, 0.5]], b1 = [0.0, 0.0]. Output layer (sigmoid): w2 = [1.0, -1.5], b2 = 0.2.

  • Hidden pre-acts: h_pre = W1x + b1 = [2.5, -0.25]
  • Hidden acts: h = ReLU(h_pre) = [2.5, 0]
  • Output pre-act: z = 1.0*2.5 + (-1.5)*0 + 0.2 = 2.7
  • Output prob: sigmoid(2.7) ≈ 0.937
Example 3: One-neuron regression (linear)

Predict house price y from size s (in 100s m²): y = w*s + b. Data point: s=8 → y_true=120. Start w=10, b=20.

  • Pred: y_hat = 10*8 + 20 = 100
  • Error: e = y_hat - y_true = -20
  • MSE gradient wrt w (for this point): 2*e*s = 2*(-20)*8 = -320
  • MSE gradient wrt b: 2*e = -40
  • With learning rate 0.01: w := 10 - 0.01*(-320) = 13.2; b := 20 - 0.01*(-40) = 20.4

Weights move to reduce error on next pass.

Exercises

Try these before opening the solutions. They mirror the Exercises section below this lesson.

  1. Forward pass (matches Exercise ex1): Compute the final probability for x = [0.5, -1.0] through a 2-2-1 network with ReLU hidden and sigmoid output, using W1 = [[1.0, -2.0],[0.5, 0.5]], b1 = [0.0, 0.0], w2 = [1.0, -1.5], b2 = 0.2.
  2. Spot overfitting (matches Exercise ex2): Train loss per epoch: [0.58, 0.42, 0.31, 0.24, 0.18, 0.12, 0.08, 0.05]; Val loss: [0.61, 0.47, 0.39, 0.36, 0.38, 0.41, 0.44, 0.50]. Is it overfitting? When would you stop? Name two regularization methods you would try.
Open general hints
  • Compute hidden activations first; apply ReLU before the output layer.
  • For overfitting, look for the validation loss minimum and divergence afterward.

Quick checklist

  • I can explain forward pass, loss, gradient, optimizer in one paragraph.
  • I know when to use sigmoid vs softmax vs linear outputs.
  • I can detect overfitting from loss curves and propose fixes.
  • I can run a minimal network and get stable training by tuning learning rate.

Common mistakes and self-check

  • Using the wrong output/loss pair. Self-check: Binary? Use sigmoid + binary cross-entropy. Multi-class? Use softmax + categorical cross-entropy. Regression? Linear + MSE/MAE.
  • Skipping normalization. Self-check: Are input features roughly standardized? If not, training may be unstable or very slow.
  • Too high learning rate. Self-check: Does loss bounce or explode? Try reducing learning rate by 10x.
  • Overfitting and no early stopping. Self-check: Does validation loss rise while training loss falls? Enable early stopping and add regularization.
  • Data leakage. Self-check: Ensure scaling/feature engineering are fit only on training data, then applied to validation/test.

Practical projects

  1. XOR classifier. Create 4 points: (0,0→0), (0,1→1), (1,0→1), (1,1→0). Train a 2-2-1 network with ReLU + sigmoid until >95% accuracy.
  2. Mini house price regression. Generate a synthetic dataset: size, rooms, age → price with noise. Train a small linear output network; report MAE on a validation split.
  3. Text sentiment toy. Create 50 short sentences labeled positive/negative. Convert to simple bag-of-words counts, train a small network with sigmoid output; evaluate accuracy and inspect confusing examples.
Tips for projects
  • Always split data into train/validation.
  • Standardize numeric features; clip extreme outliers.
  • Start small: few layers, modest learning rate (e.g., 1e-3 with Adam).

Learning path

  1. Foundations: tensors, forward pass, activations, loss.
  2. Training loop: batching, epochs, optimizer steps, monitoring metrics.
  3. Regularization: L2, dropout, early stopping, data augmentation.
  4. Architecture patterns: deeper MLPs, residual connections (conceptually).
  5. Evaluation: confusion matrix, ROC/AUC, calibration for probabilities.
  6. Deployment basics: save/load weights, set model to eval mode, measure latency.
  7. Next models: CNNs (images), RNNs/Transformers (sequences), embeddings and transfer learning.

Who this is for and prerequisites

  • Who: Aspiring and practicing Data Scientists who need a reliable neural network foundation.
  • Prerequisites: Basic Python or similar, high-school algebra, comfort with vectors/matrices, basic probability.

Mini challenge

Train a tiny network on a small dataset of your choice. Change only one thing at a time (learning rate, activation, or regularization). Write one paragraph on how that change affected validation loss and why.

Quick test

Anyone can take the test. If you log in, your progress will be saved.

When ready, start the Quick Test below.

Next steps

  • Move to convolutional and recurrent architectures once you can train a small MLP reliably.
  • Practice hyperparameter tuning: learning rate, batch size, hidden units, dropout rate.
  • Adopt good rituals: fix random seeds, track metrics, and keep training/eval logs.

Practice Exercises

2 exercises to complete

Instructions

Compute the output probability for x = [0.5, -1.0] through a 2-2-1 network with ReLU hidden and sigmoid output. Use:

  • W1 = [[1.0, -2.0], [0.5, 0.5]]
  • b1 = [0.0, 0.0]
  • w2 = [1.0, -1.5]
  • b2 = 0.2

Show intermediate hidden activations and the final probability (rounded to 3 decimals).

Expected Output
Approximately 0.937

Neural Network Basics — Quick Test

Test your knowledge with 10 questions. Pass with 70% or higher.

10 questions70% to pass

Have questions about Neural Network Basics?

AI Assistant

Ask questions about this tool