资源简介
Multiboost的Python实现
代码片段和文件信息
__author__ = ‘Thesharing‘
import math
import random
import numpy as np
import pandas
from sklearn.base import clone ClassifierMixin RegressorMixin
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import AdaBoostRegressor
from sklearn.metrics import accuracy_score
class MultiBoostClassifier:
def __init__(self base_estimator=DecisionTreeClassifier() n_estimators=10):
pandas.options.mode.chained_assignment = None
self.base_estimator = base_estimator
self.n_estimators = n_estimators
self.beta = np.empty(0)
self.error_rate = np.empty(0)
self.data_size = 0
self.y_range = np.empty(0)
self._estimators = np.empty(0)
self._class_num = 0
def fit(self X: pandas.Dataframe y):
# Initialization
self._estimators = np.empty(self.n_estimators dtype=ClassifierMixin)
self.beta = np.empty([self.n_estimators])
self.error_rate = np.empty([self.n_estimators])
self.data_size = X.shape[0]
if isinstance(y pandas.Dataframe):
y = y.values.reshape((-1))
self._get_y_dict(y)
y = self._transform_y(y)
self.y_range = np.unique(y)
# S‘ = S with instance weights assigned to be 1.
sample_X sample_y sample_weight = self._reset_sample_and_standardize(X y mode=‘uniform‘)
# set k = 1
k = 1
# for t = 1 to T {
for t in range(self.n_estimators):
# if Ik = t then
if self._get_iteration_number(k) == t:
# reset S‘ to random weights drawn from the continuous Poisson distribution.
# standardize S‘ to sum to n.
sample_X sample_y sample_weight = self._reset_sample_and_standardize(X y)
# increment k
k = k + 1
# Ct = baseLearn(S‘)
temp = clone(self.base_estimator).fit(sample_X sample_y sample_weight)
self._estimators[t] = temp
estimate_y = temp.predict(sample_X)
self.error_rate[t] = 1 - accuracy_score(sample_y estimate_y sample_weight=sample_weight)
while self.error_rate[t] > 1 - 1. / self._class_num:
# reset S‘ to random weights drawn from the continuous Poisson distribution.
# standardize S‘ to sum to n.
sample_X sample_y sample_weight = self._reset_sample_and_standardize(X y)
# increment k
k = k + 1
# go to step 8
temp.fit(sample_X sample_y sample_weight)
self._estimators[t] = temp
estimate_y = temp.predict(sample_X)
self.error_rate[t] = 1 - accuracy_score(sample_y estimate
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论