随机森林是⼀种利⽤多棵树对样本进⾏训练并预测的分类器,属于Bagging的
并⾏式集成学习⽅法。它通过有放回的采样⽅式添加样本扰动,同时引⼊属性扰
动,在基决策树的训练过程中,先从候选属性集中随机挑选出⼀个包含K个属性的
⼦集,再从这个⼦集中选择最优划分属性。随机森林中基学习器的多样性不仅来⾃
样本扰动,还来⾃属性扰动,从⽽进⼀步提升了基学习器之间的差异度。
Bootstraping/⾃助法
- Bootstraping的名称来⾃成语“pull up by your own bootstraps”,意思是依靠你⾃⼰的资源,称为⾃助法,它是⼀种有放回的重抽样⽅法。
- 附录:Bootstrap本义是指⾼靴⼦⼝后⾯的悬挂物、⼩环、 带⼦,是穿靴⼦时⽤⼿向上拉的⼯具,“pull up by your own bootstraps”即“通过拉靴⼦让⾃⼰上升”,意思是 “不可能发⽣的事情”。后来意思发⽣了转变,隐喻 “不需要外界帮助,仅依靠⾃身⼒量让⾃⼰变得更好”。
Bagging/套袋法
bootstrap aggregation
- 从样本集中重采样(有重复的)选出n个样本
- 在所有属性上,对这n个样本建⽴分类器 (ID3、C4.5、SVM、Logistic回归等)
- 重复以上两步m次,即获得了m个分类器
- 将数据放在这m个分类器上,最后根据这m个分类器的投票结果,决定数据属于哪⼀类
集成学习之结合策略
-
投票法
-
平均法
-
学习法/Stacking
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_moons
plt.rcParams['font.family'] = ['SimHei']
plt.rcParams['font.size'] = 15
plt.rcParams['axes.unicode_minus'] = False
X,y = make_moons(n_samples=500,noise=0.30,random_state=43)
# print(X)
# print(y)
X_train, X_test,y_train,y_test = train_test_split(X, y, random_state=43)
plt.figure(figsize=(10,6))
plt.plot(X[:,0][y==0],X[:,1][y==0],'yo',alpha=0.5,label='类别0')
plt.plot(X[:,0][y==1],X[:,1][y==1],'gs',alpha=