I'm studying Machine Learning using Sebastian Raschka's book.
- Wonder if someone could please help me to confirm if I have the following steps correct if I apply Perceptron Algorithm to Iris dataset as shown in the table below.
- What do I set $\eta$ to?
- What do I set $θ$ to? I randomly set it to 2.
Perceptron rule - summarized by the following steps:
- Initialize the weights to 0 or small random numbers.
For each training sample $x(i)$ perform the following steps:
Compute the output value $\hat{y}$ .
Update the weights.
\begin{array}{c|c|c|} & \text{sepal_length, $X_1$ } & \text{sepal_width, $X_2$} & \text{petal_length, $X_3$} & \text{petal_width, $X_4$} & \text{species, $Y$}\\ \hline \text{Row 0} & 5 .1 & 3.5 &1.4 &0.2 & setosa \\ \hline \text{Row 1} & 4.9 & 3.0 & 1.4 & 0.2 & setosa \\\hline \text{Row 2} & 4.7 & 3.0 & 1.4 & 0.2 & setosa \\\hline \text{Row 3} & 4.6 & 3.1 & 1.5 & 0.2 & setosa \\\hline \text{Row 4} & 5.0 & 3.6 & 1.4 & 0.2 & setosa \\\hline \end{array}
set: $θ = 2$
set: $virginica = -1,$ $\>$ $setosa = 1$
let's say if $z \ge θ,$ $\>$ $θ(z) = 1$, $\>$ $θ(z) = -1$ if otherwise
Initialize weight vector: $W$ = [ $w_1$ = 0.1, $w_2$ = 0.2, $w_3$ = 0.3, $w_4$ = 0.4]
For observation row 0:
$z = w_1*x_1 + w_2*x_2 + w_3*x_3 + w_4*x_4$ $= (0.1* 5.1) + (0.2*3.5) + (0.3*1.4) + (0.4*0.2)$ $= 1.71$
Since $z = 1.71 \lt θ = 2$, $\>$ then $θ(z) = -1$
As for row 0, the perceptron algorithm incorrectly predict $virginica = -1,$, hence the weights would be adjusted.
$w_j:= w_j + \Delta w_j$
$\Delta w_j = \eta(y^{(i)} - \hat{y}^{(i)}) x_j^{(i)}$
Hence,
$\Delta w_1 = \eta(1-(-1))5.1 = 10.2\eta$
$\Delta w_2 = \eta(1-(-1))3.5 = 7.0\eta$
$\Delta w_3 = \eta(1-(-1))1.4 = 2.8\eta$
$\Delta w_3 = \eta(1-(-1))0.2= 0.4\eta$
Update weight vector: $W$ = [ $w_1 = 0.1 + 10.2\eta$, $w_2 = 0.2 + 7.0\eta$, $w_3 = 0.3 + 2.8\eta$, $w_4 = 0.4 +0.4\eta$]
Using the updated weight to Row 1 and repeat the process above.