|
317 | 317 | "source": [
|
318 | 318 | "### Additional Note (1)\n",
|
319 | 319 | "\n",
|
| 320 | + "Please note that the learning rate η (eta) only has an effect on the classification outcome if the weights are initialized to non-zero values. If all the weights\n", |
| 321 | + "are initialized to 0, only the scale of the weight vector, not the direction. To have the learning rate influence the classification outcome, the weights need to be initialized to non-zero values. The respective lines in the code that need to be changed to accomplish that are highlighted on below:\n", |
| 322 | + "\n", |
| 323 | + "```python\n", |
| 324 | + " def __init__(self, eta=0.01, n_iter=50, random_seed=1): # add random_seed=1\n", |
| 325 | + " ...\n", |
| 326 | + " self.random_seed = random_seed # add this line\n", |
| 327 | + "\n", |
| 328 | + " def fit(self, X, y):\n", |
| 329 | + " ...\n", |
| 330 | + " # self.w_ = np.zeros(1 + X.shape[1]) ## remove this line\n", |
| 331 | + " rgen = np.random.RandomState(self.random_seed) # add this line\n", |
| 332 | + " self.w_ = rgen.normal(loc=0.0, scale=0.01, size=1 + X.shape[1]) # add this line\n", |
| 333 | + "```" |
| 334 | + ] |
| 335 | + }, |
| 336 | + { |
| 337 | + "cell_type": "markdown", |
| 338 | + "metadata": {}, |
| 339 | + "source": [ |
| 340 | + "### Additional Note (2)\n", |
| 341 | + "\n", |
320 | 342 | "I received a note by a reader who asked about the net input function:\n",
|
321 | 343 | "\n",
|
322 | 344 | ">On page 27, you describe the code.\n",
|
|
387 | 409 | "cell_type": "markdown",
|
388 | 410 | "metadata": {},
|
389 | 411 | "source": [
|
390 |
| - "### Additional Note (2)\n", |
| 412 | + "### Additional Note (3)\n", |
391 | 413 | "\n",
|
392 | 414 | "For simplicity at this point, we don't talk about shuffling at this point; I wanted to introduce concepts incrementally so that it's not too overwhelming all at once. Since a reader asked me about this, I wanted to add a note about shuffling, which you may want to use if you are using a Perceptron in practice. I borrowed the code from the `AdalineSGD` section below to modify the Perceptron algorithm accordingly (new lines are marked by trailing \"`# new`\" inline comment):\n",
|
393 | 415 | "\n",
|
|
0 commit comments