Explore Neural Networks Interactively with Quarto Live!
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:
- Modify the
set.seed()
value to generate different random data - Change the sample size from 100 to a different value
- 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:
- Input layer: The data features (x1 and x2 in this example)
- Hidden layers: The intermediate processing layers where learning occurs
- Output layer: The final prediction layer (the y value)
Building a Basic Neural Network
Key components:
- Input nodes (x1, x2) feed data into the network
- Three hidden neurons process the inputs
- An output neuron produces the prediction
- Black lines represent connections, with thickness indicating weight strength
- 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:
hidden = c(8)
for a wide, single-layer networkhidden = c(3, 3)
for a balanced two-layer network- 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:
- Quarto Live Documentation - Comprehensive guide to Quarto Live features
- WebR Documentation - Technical details about the WebR project
- Quarto Documentation - Complete information about the Quarto publishing system