Training a Single Neuron for Linear Regression

Chapter 1: Introduction and Training a Single Neuron

Linear regression is a fundamental technique in machine learning and statistics used to model the relationship between a dependent variable (y) and an independent variable (x). It fits a straight line described by the equation y = wx + b, where w (weight) and b (bias) are parameters learned from data.

x + Neuron × w +b y = wx + b

How does it work?
- The input x is multiplied by a weight w.
- A bias b (a constant) is added.
- The result y is the output.

Example:
Suppose you want to predict the price of a house based on its size:

If w = 1.5 and b = 0.5, then a house of size 2 would be predicted as:
y = 1.5 × 2 + 0.5 = 3.5
    
This means the predicted price is $350,000.

Chapter 2: Discussion about TensorFlow for JavaScript

TensorFlow.js (@tensorflow/tfjs) is the core library for building and training machine learning models in JavaScript, allowing you to run models directly in the web browser or Node.js.

tfjs-vis (@tensorflow/tfjs-vis) is a helpful visualization tool for TensorFlow.js. It lets you display charts, graphs, and metrics related to your model’s training and predictions directly in the browser.

To use them, you can include:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-vis@1.0.2/dist/tfjs-vis.umd.min.js"></script>
  

You can also load both libraries dynamically when needed. Click the button below to include both libraries (they will be used later):

Chapter 3: Introduction to the Cars Dataset

In this chapter, we will use a public dataset of cars available at:
https://storage.googleapis.com/tfjs-tutorials/carsData.json

This dataset contains information about various cars, including their miles per gallon (mpg), horsepower, and other specifications. It is commonly used for machine learning tasks such as regression, where you might predict a car's mpg based on its features.

Chapter 4: Visualizing and Splitting the Cars Dataset

In this chapter, we will visualize the relationship between a car's Horsepower and its Miles_per_Gallon (mpg) using tfjs-vis. After that, we'll split the data into training and test sets for machine learning purposes.

Chapter 5: Define an Artificial Neural Network