Explore Neural Networks Interactively with Quarto Live!

R
Quarto
Neural Networks
WebR
Visualization
Published

July 1, 2025

What is Quarto Live?

Quarto Live combines Quarto with WebR to enable interactive R code execution directly in the browser allowing for:

  • Running R code directly in the web browser
  • Instant feedback when modifying code examples
  • No installation requirements
  • Easy sharing of interactive documents

The following code blocks are fully interactive. Feel free to modify parameters and execute the code!

Creating a Simple Dataset

The first step is to create a dataset for training the neural network:

Try this:

  1. Modify the set.seed() value to generate different random data
  2. Change the sample size from 100 to a different value
  3. Add a third feature variable to the dataset

Understanding Neural Networks

Neural networks are computational models inspired by the human brain. A basic neural network consists of:

  1. Input layer: The data features (x1 and x2 in this example)
  2. Hidden layers: The intermediate processing layers where learning occurs
  3. Output layer: The final prediction layer (the y value)

Building a Basic Neural Network

Key components:

  1. Input nodes (x1, x2) feed data into the network
  2. Three hidden neurons process the inputs
  3. An output neuron produces the prediction
  4. Black lines represent connections, with thickness indicating weight strength
  5. Numbers show the actual weight values assigned to each connection

Experimenting with Different Architectures

Try modifying the hidden parameter and re-running the code snippet!

Adding Multiple Layers

Neural networks with multiple hidden layers can learn more complex patterns.

Feel free to test the following variations:

  1. hidden = c(8) for a wide, single-layer network
  2. hidden = c(3, 3) for a balanced two-layer network
  3. Experiment with hidden = c(2, 2, 2) for a deep, narrow network

Visualizing the Decision Boundary

Since the sample problem is setup as a classification problem with only 2 input parameters, the decision boundary can be visualised:

Evaluating Model Performance

This section evaluates the neural network’s performance on unseen test data:

Additional Resources

The following resources provide further information about Quarto Live and neural networks: