Linear regression and adaptive linear neurons (Adalines) are closely related to each other. Both learn a linear output by minimizing squared errors. For binary classification, Adaline adds a threshold function \(\phi_T\) that converts the continuous output into a class label. With training targets encoded as -1 and 1, we can write it as

\[\phi_T(z) = \begin{cases} 1 & \text{if } z \geq 0,\\ -1 & \text{if } z < 0. \end{cases}\]

Here, \(z\) is the net input, which is computed as the sum of the input features \(\mathbf{x}\) multiplied by the model weights \(\mathbf{w}\):

\[z = w_0x_0 + w_1x_1 + \cdots + w_mx_m = \sum_{j=0}^{m} w_jx_j = \mathbf{w}^{T}\mathbf{x}.\]

There are \(m\) input features. We include the bias weight \(w_0\) by setting the additional input \(x_0=1\).

In the case of linear regression and Adaline, the activation function \(\phi_A\) is simply the identity function, so \(\phi_A(z)=z\). Adaline uses this continuous output to compute the training error. The threshold function is applied when predicting the class label.

Linear regression and Adaline both compute a weighted sum, apply an identity activation, and use the continuous output to calculate the training error. Adaline adds a threshold after the activation to predict a class label.

Now, in order to learn the model weights \(\mathbf{w}\), we need to define a cost function that we can optimize. Here, our cost function \(J(\mathbf{w})\) is the sum of squared errors (SSE), multiplied by \(\tfrac{1}{2}\) to make the derivative easier to compute:

\[J(\mathbf{w}) = \frac{1}{2}\sum_{i=1}^{n} \left(y^{(i)}-\phi_A(z^{(i)})\right)^2.\]

Here, \(y^{(i)}\) is the target of the \(i\)th training sample \(\mathbf{x}^{(i)}\), and \(n\) is the number of samples. We use \(\hat{y}^{(i)}=\phi_A(z^{(i)})\) for the continuous prediction. This squared-error cost is both differentiable and convex in the weights.

In simple words, we can summarize batch gradient descent as follows.

  1. Initialize the weights to 0 or small random numbers.
  2. For each of \(k\) epochs (passes over the training set):
    1. Reset the accumulated weight updates to zero.
    2. For each training sample \(\mathbf{x}^{(i)}\):
      • Compute the predicted output \(\hat{y}^{(i)}\).
      • Compare it to the target \(y^{(i)}\) and compute its contribution to the weight update.
      • Add this contribution to the accumulated update.
    3. Update the weight coefficients using the accumulated values.

We keep the weights fixed while accumulating the updates within each epoch. Using the learning rate \(\eta>0\), each sample contributes to the accumulated update for weight \(w_j\) as follows:

\[\Delta w_j \leftarrow \Delta w_j+\eta\left(y^{(i)}-\hat{y}^{(i)}\right)x_j^{(i)}.\]

In mathematical notation, the steps are

  1. Initialize the weights.
  2. For each of \(k\) epochs:
    1. Set \(\Delta w_j=0\) for every weight \(j=0,\ldots,m\).
    2. For each sample \(i=1,\ldots,n\):
      • Compute \(\hat{y}^{(i)}=\phi_A(z^{(i)})\).
      • Accumulate \(\Delta w_j\) using the formula above for every weight.
    3. Apply \(\mathbf{w}\leftarrow\mathbf{w}+\Delta\mathbf{w}\).

This global update takes a step in the direction opposite to the cost gradient, scaled by the learning rate:

\[\Delta\mathbf{w}=-\eta\nabla J(\mathbf{w}).\]

The partial derivative with respect to each weight \(w_j\) is

\[\frac{\partial J}{\partial w_j} =-\sum_{i=1}^{n}\left(y^{(i)}-\hat{y}^{(i)}\right)x_j^{(i)}.\]

Let’s walk through the derivation step by step. First, the identity activation gives us a linear prediction. Using \(\ell\) as the feature index, we have

\[\hat{y}^{(i)}=\sum_{\ell=0}^{m}w_\ell x_\ell^{(i)}.\]

Only the term \(w_jx_j^{(i)}\) depends on \(w_j\). The target is independent of the weights, so

\[\frac{\partial}{\partial w_j} \left(y^{(i)}-\hat{y}^{(i)}\right)=-x_j^{(i)}.\]

We can now differentiate the squared errors using the chain rule:

\[\begin{aligned} \frac{\partial J}{\partial w_j} &=\frac{1}{2}\sum_{i=1}^{n} \frac{\partial}{\partial w_j}\left(y^{(i)}-\hat{y}^{(i)}\right)^2\\ &=\frac{1}{2}\sum_{i=1}^{n} 2\left(y^{(i)}-\hat{y}^{(i)}\right)\left(-x_j^{(i)}\right)\\ &=-\sum_{i=1}^{n} \left(y^{(i)}-\hat{y}^{(i)}\right)x_j^{(i)}. \end{aligned}\]

The factor of 2 from differentiating the square cancels the factor of \(\tfrac{1}{2}\) in the cost. Multiplying the gradient by \(-\eta\) gives the accumulated update above. The same rule applies to the bias weight \(w_0\) because \(x_0^{(i)}=1\) for every sample.