【发布时间】:2020-06-24 13:54:31
【问题描述】:
我第一次训练随机森林模型,发现了这种情况。
我在训练集上的准确率,使用默认参数(如 https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html ) 非常高,0.95 或更高,看起来很像过拟合。在测试集上,准确率达到 0.66。我的目标是减少模型的过度拟合,希望能提高测试集的性能。
我尝试执行 5 折交叉验证,使用像这里 (https://towardsdatascience.com/hyperparameter-tuning-the-random-forest-in-python-using-scikit-learn-28d2aa77dd74) 这样的随机网格搜索和以下网格:
n_estimators = [16,32,64,128]
max_features = ['auto', 'sqrt']
max_depth = [int(x) for x in np.linspace(10, 110, num = 11)]
max_depth.append(None)
min_samples_split = [2, 5, 10]
min_samples_leaf = [1, 2, 4]
bootstrap = [True, False]
random_grid = {'n_estimators': n_estimators,
'max_features': max_features,
'max_depth': max_depth,
'min_samples_split': min_samples_split,
'min_samples_leaf': min_samples_leaf,
'bootstrap': bootstrap}
最佳模型的折叠精度为 0.7。
- 我在第 2 步中对训练集和测试集使用了最佳选择的参数,但在训练集和测试集上的准确度再次为 0.95 和测试集 0.66。
有什么建议吗?你觉得这里发生了什么?如何获得结果以避免过度拟合(并可能提高模型性能)?
【问题讨论】:
-
你为什么认为你过拟合了?训练集的准确率高于测试集的准确率是可以的。
-
是的,但准确度差异很大......
-
抱歉,为什么要投反对票?请在投票前写下改进问题的建议
标签: random-forest training-data