Chapter 27: Example 1 Model

What is the “Example 1 Model”?

Example 1 Model = a single-layer, single-neuron dense model (basically a linear regressor implemented as a tiny neural network) that learns to predict:

y ≈ 2 × x (from a small noisy dataset)

In code, it looks like this (the heart of every beginner TensorFlow.js tutorial):

JavaScript

That’s it — just 2 lines to define the entire model architecture!

Why This Model is Called “Example 1 Model”

  • It is literally the first model shown in:
    • Official TensorFlow.js “Get Started” guide
    • Almost every YouTube beginner tutorial
    • Udemy, Coursera, freeCodeCamp tf.js courses
  • It proves the core promise: real training (gradient descent) happens 100% in the browser
  • It teaches the exact same concepts as a perceptron or linear regression, but using modern neural network syntax

What Does This Model Actually Contain?

After these two lines, the model has:

Part What it is How many parameters? What it learns
Input 1 number (x) 0
Dense Layer 1 neuron 2 1 weight (slope) + 1 bias
Total parameters 2 Slope ≈ 2, bias ≈ 0 (after training)

Yes — only 2 trainable numbers! That’s why it’s perfect for beginners — you can almost predict what the weights will be after training.

Full Code Again (With Extra Comments & Printouts)

HTML

What You Should See After Clicking “Train the Model”

In the <pre> area and console:

text

Why This Tiny Model Teaches You So Much

  • You see only 2 parameters → easy to understand what “learning” means
  • You watch loss drop dramatically → feel the power of gradient descent
  • You can manually calculate what the model learned → weight ≈ 2, bias ≈ 0
  • You predict on new data → see generalization in action

In 2026, this Example 1 Model is still the perfect starting point because:

  • It proves tf.js can train models in browser
  • It uses the exact same sequential → add → compile → fit → predict pattern as every bigger model
  • It builds intuition for weights, bias, loss, epochs, optimizer

Got it completely now? 🌟

Want next?

  • Add tfjs-vis live loss graph to this exact model?
  • Change it to multiple inputs (e.g., flat size + bedrooms → price)?
  • Show how to save/load this tiny model?

Just tell me — next class is ready! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *