8000 修改Chapter1 · tao-to-python/Learning-from-data@dd14fe3 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd14fe3

Browse files
committed
修改Chapter1
1 parent 8a98f0f commit dd14fe3

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed
-10.1 KB
Binary file not shown.

Chapter1/md/Chapter 1 The Learning Problem.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def Judge(X, y, w):
139139

140140
def data(N, d, rnd, t=0.1):
141141
"""
142-
生成N个d维点(不包括偏置项1),x1+...+xd>=t的点标记为+1,x1+...+xd<=-t的点标记为-1
142+
生成N个d维点(不包括偏置项1),x1+...+xd>=t的点标记为+1,x1+...+xd<=-t的点标记为-1,
143+
rnd为随机数生成器,形式为rnd = np.random.RandomState(seed),seed为随机种子,
143144
"""
144145
X = []
145146
w = np.ones(d)
@@ -158,7 +159,8 @@ def data(N, d, rnd, t=0.1):
158159
def f(N, d, rnd, t=0.1, r=1):
159160
"""
160161
生成N个d维点(不包括偏置项1),x1+...+xd>=t的点标记为+1,x1+...+xd<=-t的点标记为-1,
161-
rnd为随机数生成器,利用PLA更新,如果r=1,那么按照顺序取点,否则随机取点
162+
rnd为随机数生成器,形式为rnd = np.random.RandomState(seed),seed为随机种子,
163+
利用PLA更新,如果r=1,那么按照顺序取点,否则随机取点
162164
"""
163165
X, y = data(N, d, rnd, t=t)
164166

@@ -190,19 +192,6 @@ def f(N, d, rnd, t=0.1, r=1):
190192

191193
#返回数据
192194
return a, b, c, X, y, s, w
193-
194-
def plot_helper(a, b, c, X, y, s, w, t=0.1):
195-
"""
196-
作图函数
197-
"""
198-
#画出图像
199-
plt.scatter(X[y == 1][:, 1], X[y == 1][:, 2], c='r', s=1)
200-
plt.scatter(X[y == -1][:, 1], X[y == -1][:, 2], c='b', s=1)
201-
plt.plot(a, b, label="("+str(w[0])+")+("+str(w[1])+")x1+("+str(w[2])+")x2=0")
202-
plt.plot(a, c, label="x1+x2="+str(t))
203-
plt.title(u"经过"+str(s)+u"次迭代收敛")
204-
plt.legend()
205-
plt.show()
206195
```
207196

208197
最后的代码如下

0 commit comments

Comments
 (0)
0