boosting.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:Adaboost 作者: shzygmyx 项目源码 文件源码
def train(self):
        m = self.m
        for k in range(self.itern):
            cls = self.estimator(max_depth = 3, presort = True)
            cls.fit(self.X, self.y, sample_weight = self.w)
            self.estimators.append(cls)
            y_predict = cls.predict(self.X) 
            error = 0  # number of wrong prediction
            for i in range(m):
                if y_predict[i] != self.y[i]:
                    error += self.w[i]
            if error == 0:
                error += 0.01 # smoothness
            alpha = 0.5*log((1-error)/error) # estimator weight
            self.alphas = np.append(self.alphas, alpha)
            for i in range(m): # update sample weights
                if y_predict[i] != self.y[i]:
                    self.w[i] *= e**alpha
                else:
                    self.w[i] /= e**alpha
            self.w /= sum(self.w)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号