Skip to content

Commit

Permalink
add note about random weights
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Sep 21, 2016
1 parent 7c4b318 commit fc790b7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion code/ch02/ch02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,28 @@
"source": [
"### Additional Note (1)\n",
"\n",
"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",
"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",
"\n",
"```python\n",
" def __init__(self, eta=0.01, n_iter=50, random_seed=1): # add random_seed=1\n",
" ...\n",
" self.random_seed = random_seed # add this line\n",
"\n",
" def fit(self, X, y):\n",
" ...\n",
" # self.w_ = np.zeros(1 + X.shape[1]) ## remove this line\n",
" rgen = np.random.RandomState(self.random_seed) # add this line\n",
" self.w_ = rgen.normal(loc=0.0, scale=0.01, size=1 + X.shape[1]) # add this line\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Additional Note (2)\n",
"\n",
"I received a note by a reader who asked about the net input function:\n",
"\n",
">On page 27, you describe the code.\n",
Expand Down Expand Up @@ -387,7 +409,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Additional Note (2)\n",
"### Additional Note (3)\n",
"\n",
"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",
"\n",
Expand Down

0 comments on commit fc790b7

Please sign in to comment.