- 所有弱分类器的结果相加等于预测值。
- 每次都以当前预测为基准,下一个弱分类器去拟合误差函数对预测值的残差(预测值与真实值之间的误差)。
- GBDT的弱分类器使用的是树模型。
第一棵树,原数据根据一个特征预测,产生残差;第二棵树,残差根据第二个特征预测,产生残差
GBDT需要将多棵树的得分累加得到最终的预测得分,且每轮迭代,都是在现有树的基础上,增加一棵新的树去拟合前面树的预测值与真实值之间的残差
特点:
每棵树结构确定,可并行化计算,计算速度快,但训练过程无法并行
在稠密,数值型数据上效果好,反之,效果差,对异常值特别敏感
可解释性强
# 使用Sklearn调用GBDT模型拟合数据并可视化
import numpy as np
import pydotplus
from sklearn.ensemble import GradientBoostingRegressor
X = np.arange(1, 11).reshape(-1, 1)
y = np.array([5.16, 4.73, 5.95, 6.42, 6.88, 7.15, 8.95, 8.71, 9.50, 9.15])
gbdt = GradientBoostingRegressor(max_depth=4, criterion ='squared_error').fit(X, y)
from IPython.display import Image
from pydotplus import graph_from_dot_data
from sklearn.tree import export_graphviz
# 拟合训练5棵树
sub_tree = gbdt.estimators_[4, 0]
dot_data = export_graphviz(sub_tree, out_file=None, filled=True, rounded=True, special_characters=True, precision=2)
graph = pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())