|
@@ -141,11 +141,25 @@ |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"cell_type": "code", |
|
|
"cell_type": "code", |
|
|
"execution_count": null, |
|
|
|
|
|
|
|
|
"execution_count": 1, |
|
|
"metadata": { |
|
|
"metadata": { |
|
|
"lines_to_end_of_cell_marker": 2 |
|
|
"lines_to_end_of_cell_marker": 2 |
|
|
}, |
|
|
}, |
|
|
"outputs": [], |
|
|
|
|
|
|
|
|
"outputs": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "stdout", |
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
"text": [ |
|
|
|
|
|
"update weight and bias: 1.0 3.0 0.5\n", |
|
|
|
|
|
"update weight and bias: -0.5 2.5 0.0\n", |
|
|
|
|
|
"update weight and bias: -2.5 2.0 -0.5\n", |
|
|
|
|
|
"w = [-2.5, 2.0]\n", |
|
|
|
|
|
"b = -0.5\n", |
|
|
|
|
|
"[ 1 1 1 1 -1 -1 -1 -1]\n", |
|
|
|
|
|
"[1, 1, 1, 1, -1, -1, -1, -1]\n" |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
"source": [ |
|
|
"source": [ |
|
|
"import random\n", |
|
|
"import random\n", |
|
|
"import numpy as np\n", |
|
|
"import numpy as np\n", |
|
@@ -163,6 +177,7 @@ |
|
|
" train_num = n_iter # 迭代次数\n", |
|
|
" train_num = n_iter # 迭代次数\n", |
|
|
"\n", |
|
|
"\n", |
|
|
" for i in range(train_num):\n", |
|
|
" for i in range(train_num):\n", |
|
|
|
|
|
" #FIXME: the random chose sample is to slow\n", |
|
|
" train = random.choice(train_data)\n", |
|
|
" train = random.choice(train_data)\n", |
|
|
" x1, x2, y = train\n", |
|
|
" x1, x2, y = train\n", |
|
|
" predict = sign(weight[0] * x1 + weight[1] * x2 + bias) # 输出\n", |
|
|
" predict = sign(weight[0] * x1 + weight[1] * x2 + bias) # 输出\n", |
|
|