(十四、)极限森林

2020-04-07  本文已影响0人  羽天驿

一、极限森林

特征随机
参数随机
分裂随机
因为分裂是随机的,所以就不需要样本是随机的了

二、代码的实现

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)
output_6_0.png
# 第二颗树样本:45,55,33
plt.figure(figsize=(9,7))
_ = tree.plot_tree(clf3[1],filled=True)
output_7_0.png
# 第三颗树样本:45,55,33
plt.figure(figsize=(9,7))
_ = tree.plot_tree(clf3[2],filled=True)
output_8_0.png
上一篇 下一篇

猜你喜欢

热点阅读