一、极限森林
特征随机
参数随机
分裂随机
因为分裂是随机的,所以就不需要样本是随机的了
- 随机森林和极限森林不同之处:
- 随机森林样本抽样,随机性,而极限森林样本都是固定的
- 随机森林在分裂的时候,best;极限森林 分裂方式是:random
- 其他的都是一样的。
- 好处:
- 降低模型方差,模型更加稳定(高中同学考试为例,张三,发挥不稳定),鲁棒性增强robust。
- 偏差变大。集成算法多颗树,有的树,选择类别0,有的选择类别1,最终统计:众数
- 提升模型的准确率
二、代码的实现
import warnings
warnings.filterwarnings('ignore')
import numpy as np
from sklearn.ensemble import RandomForestClassifier,ExtraTreesClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn import datasets
from sklearn import datasets
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn import tree
X,y = datasets.load_wine(True)
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 119)
clf = DecisionTreeClassifier()
clf.fit(X_train,y_train)
clf.score(X_test,y_test)
0.9333333333333333
clf2 = RandomForestClassifier()
clf2.fit(X_train,y_train)
clf2.score(X_test,y_test)
1.0
随机森林,随机抽样
极限森林,不仅有随机抽样,属性裂分随机
'''max_features : int, float, string or None, optional (default="auto")
The number of features to consider when looking for the best split:'''
clf3 = ExtraTreesClassifier(max_depth=3,max_features=1)
clf3.fit(X_train,y_train)
clf3.score(X_test,y_test)
0.9777777777777777
# 第一颗树样本:45,55,33
plt.figure(figsize=(9,7))
_ = tree.plot_tree(clf3[0],filled=True)
![](https://img-blog.csdnimg.cn/img_convert/5498af31b31363fc1b6ef073c55486ad.webp?x-oss-process=image/format,png)
output_6_0.png
# 第二颗树样本:45,55,33
plt.figure(figsize=(9,7))
_ = tree.plot_tree(clf3[1],filled=True)
![](https://img-blog.csdnimg.cn/img_convert/a9c9618a18d0e248ccaa48d084d88194.webp?x-oss-process=image/format,png)
output_7_0.png
# 第三颗树样本:45,55,33
plt.figure(figsize=(9,7))
_ = tree.plot_tree(clf3[2],filled=True)
![](https://img-blog.csdnimg.cn/img_convert/1a7f742c016760e29bd5ce6ae5f46375.webp?x-oss-process=image/format,png)
output_8_0.png