|
|
|
@@ -119,17 +119,22 @@ |
|
|
|
"\n", |
|
|
|
"\n", |
|
|
|
"算法\n", |
|
|
|
"```\n", |
|
|
|
"\n", |
|
|
|
"\n", |
|
|
|
"输入:T={(x1,y1),(x2,y2)...(xN,yN)}(其中xi∈X=Rn,yi∈Y={-1, +1},i=1,2...N,学习速率为η)\n", |
|
|
|
"\n", |
|
|
|
"输出:w, b;感知机模型f(x)=sign(w·x+b)\n", |
|
|
|
"(1) 初始化w0,b0\n", |
|
|
|
"(2) 在训练数据集中选取(xi, yi)\n", |
|
|
|
"(3) 如果yi(w * xi+b)≤0\n", |
|
|
|
" w = w + ηyixi\n", |
|
|
|
" b = b + ηyi\n", |
|
|
|
"(4) 如果所有的样本都正确分类,或者迭代次数超过设定值,则终止\n", |
|
|
|
"(5) 否则,跳转至(2)\n", |
|
|
|
"```\n", |
|
|
|
"\n", |
|
|
|
"1. 初始化$w_0$,$b_0$\n", |
|
|
|
"2. 在训练数据集中选取$(x_i, y_i)$\n", |
|
|
|
"3. 如果$y_i(w * x_i+b)≤0$\n", |
|
|
|
" \n", |
|
|
|
" $w = w + η y_i x_i$\n", |
|
|
|
" \n", |
|
|
|
" $b = b + η y_i$\n", |
|
|
|
"\n", |
|
|
|
"4. 如果所有的样本都正确分类,或者迭代次数超过设定值,则终止\n", |
|
|
|
"5. 否则,跳转至(2)\n", |
|
|
|
"\n" |
|
|
|
] |
|
|
|
}, |
|
|
|
@@ -142,7 +147,7 @@ |
|
|
|
}, |
|
|
|
{ |
|
|
|
"cell_type": "code", |
|
|
|
"execution_count": 3, |
|
|
|
"execution_count": 1, |
|
|
|
"metadata": { |
|
|
|
"lines_to_end_of_cell_marker": 2 |
|
|
|
}, |
|
|
|
@@ -151,13 +156,10 @@ |
|
|
|
"name": "stdout", |
|
|
|
"output_type": "stream", |
|
|
|
"text": [ |
|
|
|
"update weight and bias: 1.0 2.5 0.5\n", |
|
|
|
"update weight and bias: -2.5 1.0 0.0\n", |
|
|
|
"update weight and bias: -1.5 3.5 0.5\n", |
|
|
|
"update weight and bias: -5.0 2.0 0.0\n", |
|
|
|
"update weight and bias: -4.0 4.5 0.5\n", |
|
|
|
"w = [-4.0, 4.5]\n", |
|
|
|
"b = 0.5\n", |
|
|
|
"update weight and bias: 1.0 3.0 0.5\n", |
|
|
|
"update weight and bias: -2.5 1.5 0.0\n", |
|
|
|
"w = [-2.5, 1.5]\n", |
|
|
|
"b = 0.0\n", |
|
|
|
"ground_truth: [1, 1, 1, 1, -1, -1, -1, -1]\n", |
|
|
|
"predicted: [1, 1, 1, 1, -1, -1, -1, -1]\n" |
|
|
|
] |
|
|
|
@@ -248,7 +250,7 @@ |
|
|
|
"name": "python", |
|
|
|
"nbconvert_exporter": "python", |
|
|
|
"pygments_lexer": "ipython3", |
|
|
|
"version": "3.6.8" |
|
|
|
"version": "3.6.9" |
|
|
|
} |
|
|
|
}, |
|
|
|
"nbformat": 4, |
|
|
|
|