相关疑难解决方法(0)

为什么具有单个树的Random Forest比决策树分类器好得多?

我通过scikit-learn图书馆学习机器学习.我使用以下代码将决策树分类器和随机森林分类器应用于我的数据:

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)
Run Code Online (Sandbox Code Playgroud)

为什么随机森林分类器的结果更好(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 …
Run Code Online (Sandbox Code Playgroud)

python machine-learning decision-tree random-forest scikit-learn

9
推荐指数
1
解决办法
1441
查看次数