【发布时间】:2018-06-22 16:22:22
【问题描述】:
我应用 使用以下代码对我的数据进行决策树分类器和随机森林分类器:
def decision_tree(train_X, train_Y, test_X, test_Y):
clf = tree.DecisionTreeClassifier()
clf.fit(train_X, train_Y)
return clf.score(test_X, test_Y)
def random_forest(train_X, train_Y, test_X, test_Y):
clf = RandomForestClassifier(n_estimators=1)
clf = clf.fit(X, Y)
return clf.score(test_X, test_Y)
为什么随机森林分类器的结果要好得多(运行 100 次,随机抽样 2/3 的数据用于训练,1/3 用于测试)?
100%|███████████████████████████████████████| 100/100 [00:01<00:00, 73.59it/s]
Algorithm: Decision Tree
Min : 0.3883495145631068
Max : 0.6476190476190476
Mean : 0.4861783113770316
Median : 0.48868030937802126
Stdev : 0.047158171852401135
Variance: 0.0022238931724605985
100%|███████████████████████████████████████| 100/100 [00:01<00:00, 85.38it/s]
Algorithm: Random Forest
Min : 0.6846846846846847
Max : 0.8653846153846154
Mean : 0.7894823428836184
Median : 0.7906101571063208
Stdev : 0.03231671150915106
Variance: 0.0010443698427656967
具有一个估计器的随机森林估计器不只是一棵决策树吗? 我做错了什么或误解了这个概念吗?
【问题讨论】:
-
这取决于您用于随机森林的参数。随机森林意味着使用许多树。它效率不高。 Xgboost 对许多树进行纠错。目标不是效率是减少错误的策略。
标签: python machine-learning scikit-learn random-forest decision-tree