我正在用 Python 从头开始编写 AdaBoost。您能否详细说明该行self.functions[0] = f_0
导致错误的原因?
class AdaBoost_regressor():
def __init__(self, n_estimators, functions):
# n_estimators is the number of weak regressors
self.n_estimators = n_estimators
# We will store the sequence of functions in object "functions"
self.functions = np.array([None] * n_estimators, dtype = 'f')
# We set f_0 = 0
def f_0(x):
return 0
self.functions[0] = f_0
结果是NameError: name 'self' is not defined
。
我认为你出错的原因是你不能self
在方法之外的类中使用,因为为了使用self
类的实例必须作为参数传递给某个函数。
请注意,在初始化类之前,表达式没有任何意义self
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句