import numpy as np
W_1 = 0.1 * np.ones(10) # 初始权值
x = np.arange(10)
y = np.array([1,1,1,-1,-1,-1,1,1,1,-1])
def G_1(x):
"""弱分类器1"""
if x < 2.5:
return 1
else:
return -1
print([G_1(xi) for xi in x]) # 分错3个
[1, 1, 1, -1, -1, -1, -1, -1, -1, -1]
def e(W, y, G):
"""计算分类误差"""
e